Hyperlink in datagrid view

I want to set a hyperlink field in a datagrid view. When the user clicks on this link, a query string should be generated, and the user should be redirected to another page. So how can I set a hyperlink to create a query string?

+6
source share
3 answers

you can do as ...

<ItemTemplate> <asp:HyperLink ID="Edit" runat="server" Text="Edit" NavigateUrl='<%# Eval("DataKeyName", "~/View.aspx?Id={0}") %>' /> </ItemTemplate> 
+4
source
 <asp:GridView ID="Griddata" runat="server" AutoGenerateColumns="False" CellPadding="1" GridLines="Horizontal" Width="1000px" ShowFooter="True" CssClass="grid" AlternatingRowStyle-CssClass="alt"> <Columns> <asp:HyperLinkField HeaderText="ID" DataTextField="rec_id" DataNavigateUrlFields="rec_id" DataNavigateUrlFormatString="followme.aspx?record={0} " /> <asp:BoundField HeaderText="Login" DataField="LoginName"></asp:BoundField> </Columns> </asp:GridView> 

This is an example of a gridview defined in ASP.NET
You must specify <asp:Hyperlinkfield> in the column definition.

In this field you need to specify the DataTextfield (which will be displayed on the screen in this column), your URL ( DataNavigateUrlFormatString ) and your parameter that you want to use in the URL ( DataNavigateUrlFields )

Note. I am attached to this grid from the code, and not through SqlDatAdaptor , but the result is the same.

You will get something like this:

sample bound URL

+9
source
 <a href='page.aspx?id=<#Eval("ID")>'>click</a> 
+1
source

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


All Articles