rossryan
asked on
GridView: Programmatically adding columns to the control (HyperLink)
Hi,
Minor problem here. I am trying to find a way to add programmatically columns to a GridView control. Most of the code I have read on the internet is unclear here.
Suppose I have a datatable filled with the following ids:
23424323
45645646
13123212
And I need to render a hyperlink as part of the gridview, where there is a column of hyperlinks like "edit.aspx?id=23424323", preferably with just the word "edit" showing.
Thanks,
Ryan
Minor problem here. I am trying to find a way to add programmatically columns to a GridView control. Most of the code I have read on the internet is unclear here.
Suppose I have a datatable filled with the following ids:
23424323
45645646
13123212
And I need to render a hyperlink as part of the gridview, where there is a column of hyperlinks like "edit.aspx?id=23424323", preferably with just the word "edit" showing.
Thanks,
Ryan
ASKER
Programmatically.
sorry there is typo use it as
<asp:HyperLink ID="hpl" runat="server" Text="Edit" NavigateUrl='<%# "edit.aspx?id=" + Eval("DBField") %>'></asp:HyperLink>
<asp:HyperLink ID="hpl" runat="server" Text="Edit" NavigateUrl='<%# "edit.aspx?id=" + Eval("DBField") %>'></asp:HyperLink>
ASKER
Hmm. Perhaps I should explain it like this:
I am looking for any code that let's me dynamically create those columns. What I mean is, I'm slotting this into a web control, and I do not know beforehand just how many columns will be hyperlink columns. The number of columns will be determined by the value I receive when the control is created.
Thanks,
Ryan
I am looking for any code that let's me dynamically create those columns. What I mean is, I'm slotting this into a web control, and I do not know beforehand just how many columns will be hyperlink columns. The number of columns will be determined by the value I receive when the control is created.
Thanks,
Ryan
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I want to show you that you can add columns to your GridView in a easy way. This must be done before call GridView.DataBind() method.
HyperLinkField linkColumn = new HyperLinkField();
linkColumn.HeaderText = "Column Title";
GridView1.Columns.Add(linkColumn);
Please use following
Thansk
Open in new window