3

有人可以向我解释如何在使用 C# 生成的代码生成的 GridView中将边界字段 () 包含Emp_ID到 HyperLinkField ( ) 中吗?IDNumber这样 url 字符串将是'../Pages/Home.aspx?Emp_ID=(Emp_ID)'>(IDNumber)</a>

谢谢

片段代码如下:

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);
4

1 回答 1

2

您要做的是设置 DataNavigateUrlFormatString 而不是 DataTextFormatString。

string[] id = new string[] { "Emp_ID" }; 

HyperLinkField hyperlinkedColumn = new HyperLinkField();
hyperlinkedColumn.DataTextField = "IDNumber";
hyperlinkedColumn.HeaderText = "ID No.";
hyperlinkedColumn.DataNavigateUrlFields = id;
hyperlinkedColumn.DataNavigateUrlFormatString = "../Pages/Home.aspx?Emp_ID={0}";
hyperlinkedColumn.Visible = true;
于 2010-10-15T15:08:19.620 回答