asp.netvb.netgridviewquery-stringnavigateurl

Set NavigateUrl in RowDataBound event


I currently have a gridview with a column of hyperlinks to edit and delete a customer. I need to use hyperlinks in my case, but was wondering how else I could pass other values to the pages I go to? Right now I can pass table values, but what about if I want to pass other data? Such as the my pagesort, index, and searchfields, to use when returning to the page?

Right now I am using session to take care of the above, but was told to use query strings for the values instead and was not sure of the best approach.

<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="EditLink" runat="server" Text="Edit"
  NavigateUrl='<%# "~/EditCustomer.aspx?ID=" & DataBinder.Eval(Container.DataItem, "MasterContactID")%>' />
<asp:HyperLink ID="Delete" runat="server" Text="Delete"
  NavigateUrl='<%# "~/DeleteCustomer.aspx?ID=" & DataBinder.Eval(Container.DataItem, "MasterContactID")%>' />
</ItemTemplate>
</asp:TemplateField>

Solution

  • It depends - you can change it to a button, and on RowCommand event, you can store some key data in Session, then redirect. OR, you can put everything in querystring, but if you have a lot of fields to pass to the other page, I would use a button (or link button), give it a command name, in Grid_RowCommand, store the values in session and redirect, then retrieve and delete the session variables after redirected.