I have a gridview and added a column "Hyperlink" to all records by enabling autogeneratefields. When this gridview is loaded and when I click the hyperlink across any record I want to redirect to some other page with entire record passed as query string to that page? can anybody help me on this?
1 Answer
These links should clarify how to do it:
How to pass variables thru a DataGrid hyperlink column
How To: Use a HyperLink control inside a GridView
Sample code (Look at the NavigateUrl property of HyperLink):
<asp:GridView ID="urlGrid" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1"
runat="server"
NavigateUrl='<%# "RedirectPage.aspx?xxxx=" &
DataBinder.Eval(Container, "DataItem.xxxx") &
"&yyyy=" & DataBinder.Eval(Container, "DataItem.yyyy")%>'
Text="Go!">
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="SiteName" HeaderText="Site Name" />
</Columns>
</asp:GridView>
2 Comments
krishna
Am not passing any variables to hyperlink column.The thing is that when I click the link across any record i have to be redirected to some other page with the record as querysting. supposing you have a gridview of the following format, Name Address xxxx yyyyy BID aaaa bbbbb BID when I click the BID link at the first record,it should be directed to next page with xxxx,yyyy as querystring. thanks
Leniel Maccaferri
The pages I linked above show you how to do just that... You can choose which row fields you want to be passed in the query string.