How to Dynamic add html in GridView by c# code????
-
Dear Friend, I am working on GridView in c#. Getting a problem on dynamic add html in a GridView Columns. How can I make a dynamic template by coding??? Many thanks.
DataTable dt = new DataTable(); dt.Columns.Add("Id", Type.GetType("System.Int32")); dt.Columns.Add("Detail", Type.GetType("System.String")); dr = dt.NewRow(); dr["Id"] = id; dr["Detail"] = "<a href='home.aspx#" + id + "' >Detail</a>"; dt.Rows.Add(dr); gridView.DataSource = dt; gridView.DataBind();
-
Dear Friend, I am working on GridView in c#. Getting a problem on dynamic add html in a GridView Columns. How can I make a dynamic template by coding??? Many thanks.
DataTable dt = new DataTable(); dt.Columns.Add("Id", Type.GetType("System.Int32")); dt.Columns.Add("Detail", Type.GetType("System.String")); dr = dt.NewRow(); dr["Id"] = id; dr["Detail"] = "<a href='home.aspx#" + id + "' >Detail</a>"; dt.Rows.Add(dr); gridView.DataSource = dt; gridView.DataBind();
Use a HyperLinkField;
HyperLinkField detailLink = new HyperLinkField();
detailLink.NavigateUrl = string.Format("home.aspx#{0}", id);
detailLink.Text = "Detail";
gridView.Columns.Add(detailLink);You will also need to set the
AutoGenerateColumns
to false and create a BoundField for the id column.