Click here to Skip to main content
15,888,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have one query. I am supposed to put hyperlink in a gridview so that that link can redirect to particular user profile. Can somebody please resolve this problem for me as soon as possible? Thanks in advance?

What I have tried:

studentprofile.aspx

ASP.NET
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
              CellPadding="4" ForeColor="#333333" GridLines="None" Width="178px">
             <alternatingrowstyle backcolor="White" />
        <columns>
            <asp:HyperLinkField Text="Profile" />
            <asp:BoundField DataField="Fname" HeaderText="Name" />
            <asp:BoundField DataField="Lname" HeaderText="Last Name" />
            <asp:ImageField DataImageUrlField="Pic" HeaderText="Profile">
                <controlstyle height="70px" width="70px" />
            
        </columns>
             <editrowstyle backcolor="#2461BF" />
             <footerstyle backcolor="#507CD1" font-bold="True" forecolor="White" />
             <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
             <pagerstyle backcolor="#2461BF" forecolor="White" horizontalalign="Center" />
             <rowstyle backcolor="#EFF3FB" />
             <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
             <sortedascendingcellstyle backcolor="#F5F7FB" />
             <sortedascendingheaderstyle backcolor="#6D95E1" />
             <sorteddescendingcellstyle backcolor="#E9EBEF" />
             <sorteddescendingheaderstyle backcolor="#4870BE" />




studentprofile.aspx.cs


C#
protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        SqlConnection cn = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
        cn.Open();
        SqlCommand cmd = new SqlCommand("SELECT Registration1.Fname, Registration1.Lname, alumniregister.Pic, studentregister.Pic AS Expr1 FROM Registration1 FULL OUTER JOIN alumniregister ON Registration1.r_ID = alumniregister.r_ID FULL OUTER JOIN studentregister ON Registration1.r_ID = studentregister.r_ID where Fname like '" + TextBox1.Text + "%' or Lname like '" + TextBox1.Text + "%' ", cn);
        SqlDataReader dr = cmd.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        cn.Close();
    }
Posted
Updated 29-Apr-16 1:30am
v2
Comments

1 solution

I googled "create htperlink gridview" and found this link as well as many others

c# - how to create a link in gridview in asp.net - Stack Overflow[^]

Please do some basic research before asking a question, and at least attempt to solve the issue yourself before expecting other people to do your work for you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900