边界字段作为代码生成的网格视图中超链接字段的一部分
有人可以向我解释一下如何在使用 C# 生成的 GridView 代码中将绑定字段 (Emp_ID
) 包含到 HyperLinkField (IDNumber
) 中吗?这样 url 字符串将是 '../Pages/Home.aspx?Emp_ID=(Emp_ID)'>(IDNumber)
谢谢
下面的代码片段:
IDColumn.DataField = "Emp_ID";
IDColumn.HeaderText = "Emp_ID";
string[] id = new string[] { "Emp_ID" };
IDColumn.Visible = false;
grid.Columns.Add(IDColumn);
hyperlinkedColumn.DataTextField = "IDNumber";
hyperlinkedColumn.HeaderText = "ID No.";
hyperlinkedColumn.DataNavigateUrlFields = id;
hyperlinkedColumn.DataTextFormatString = "<a href='../Pages/Home.aspx?Emp_ID='>{0}</a>";
hyperlinkedColumn.Visible = true;
grid.DataKeyNames = id;
grid.Columns.Add(hyperlinkedColumn);
Can someone please explain to me how I can include a boundfield (Emp_ID
) to the HyperLinkField (IDNumber
) in a code generated GridView using C#? So that the url string would be '../Pages/Home.aspx?Emp_ID=(Emp_ID)'>(IDNumber)</a>
Thanks
Snippet code below:
IDColumn.DataField = "Emp_ID";
IDColumn.HeaderText = "Emp_ID";
string[] id = new string[] { "Emp_ID" };
IDColumn.Visible = false;
grid.Columns.Add(IDColumn);
hyperlinkedColumn.DataTextField = "IDNumber";
hyperlinkedColumn.HeaderText = "ID No.";
hyperlinkedColumn.DataNavigateUrlFields = id;
hyperlinkedColumn.DataTextFormatString = "<a href='../Pages/Home.aspx?Emp_ID='>{0}</a>";
hyperlinkedColumn.Visible = true;
grid.DataKeyNames = id;
grid.Columns.Add(hyperlinkedColumn);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的是设置 DataNavigateUrlFormatString 而不是 DataTextFormatString。
What you are going to want to do is set the DataNavigateUrlFormatString instead of DataTextFormatString.