有人可以向我解释如何在使用C#的代码生成的GridView中向HyperLinkField(Emp_ID
)添加boundfield(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);
答案 0 :(得分: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;