Imran Pollob Imran Pollob - 3 months ago 61
MySQL Question

how to each row in gridview makes a hyperlink to another action in asp.net?

I am a beginner in asp.net. The problem is silly for experts I think.
The problem is I have a student table in mysql. student table has a column named "batch". When user search for a batch then the students names from that batch comes to a gridview table.

Now i a want to make link for every column so that if user click a row of table,then the full profile of that student shows in a new page.

How can I make the rows as Hyperlink?

Win Win
Answer

You question is too broad.

want to make link for every column so that if user click a row of table,then the full profile of that student shows in a new page

Redirecting user to a new page just by single clicking on a row is not user friendly.

Instead, you can create a hyperlink in a cell. When a user clicks on a link, then redirect the user to details page.

You can use either HyperLinkField or TemplateField to create a link in GridView. For example -

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False">
    <Columns>
        <asp:HyperLinkField
            DataNavigateUrlFields="Batch"
            DataNavigateUrlFormatString="~/Details.aspx?id={0}"
            DataTextField="Batch"
            DataTextFormatString="{0}">
        </asp:HyperLinkField>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:HyperLink runat="server" ID="HyperLink1"
                    NavigateUrl='~/Details.aspx?id=<%# Eval("Batch") %>'>
                    <%# Eval("Batch") %>
                </asp:HyperLink>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

FYI: some people use double clicking feature on row, but it is a little bit tricky if you are new to ASP.Net

Comments