Boundfield as part of Hyperlinkfield in code-generated gridview

Can someone explain to me how I can include the border field ( Emp_ID) in HyperLinkField ( IDNumber) in the generated GridView using C #? So the url string will be'../Pages/Home.aspx?Emp_ID=(Emp_ID)'>(IDNumber)</a>

thank

Fragment 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);
+3
source share
1 answer

What you need to do is set DataNavigateUrlFormatString instead of 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;
+2
source

Source: https://habr.com/ru/post/1769691/


All Articles