jpavlov
jpavlov

Reputation: 2261

how to add a hyper link in a gridview

I have a gridview control and I would like the field Title to be a hyperlink and execute a stored procedure when clicked. Can anyone assist me in this?

Does this code look right?

<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <asp:HyperLink ID="hpTitle" runat="server" Text='<%# Bind("Title") %>' NavigateUrl='<%# Bind("SelectBook") %>'></asp:HyperLink>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
    <asp:BoundField DataField="Publisher" HeaderText="Publisher" SortExpression="Publisher" />
    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
</Columns>

Upvotes: 0

Views: 410

Answers (1)

Saurabh
Saurabh

Reputation: 5727

<asp:TemplateField>
                <ItemTemplate>
                <asp:HyperLink id="hplink" runat="server" Text='<%# Bind("columnname")%>' NavigateUrl='<%# Bind("columnname")%>'></asp:HyperLink>
                </ItemTemplate>
            </asp:TemplateField>

On NavigateUrl, you can redirect to any page and on page_load you can call any stored procedure by using SQlCommand Object.

Upvotes: 1

Related Questions