Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hyperlink in datagrid view

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

like image 541
Microsoft Developer Avatar asked May 20 '11 10:05

Microsoft Developer


2 Answers

you can do like...

<ItemTemplate>
<asp:HyperLink ID="Edit" runat="server" Text="Edit" NavigateUrl='<%# Eval("DataKeyName", "~/View.aspx?Id={0}") %>' />
</ItemTemplate>
like image 45
Muhammad Akhtar Avatar answered Oct 12 '22 03:10

Muhammad Akhtar


<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 a sample GridView defined in ASP.NET
You need to specify the <asp:Hyperlinkfield> in the column definition.

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

Note: I'm binding to this grid from code-behind, not through a SqlDatAdaptor but the result is the same.

You will get something like this:

sample bound URL

like image 103
KriZ Avatar answered Oct 12 '22 03:10

KriZ