I have a pair of questions.. I am quite new to this gridview in asp.net using C#.. I have used the following code to bind the sql database table from my gridview.

SqlDataAdapter da = new SqlDataAdapter("select customerid, customername from table",con);
ds.Clear();
da.Fill(ds);
gridview.datasource=ds;
gridview.databind();

And set the autogenerate columns property to false then add a databound with a datafield that pertains to a column of my table.

1.) How to make the rows of a specific column to be hyperlink. I believe it goes something like <asp:Hyperlink>.

2.) After making the rows of a column to be hyperlink, how could I redirect the link to its corresponding page? What I mean is, if I click a hyperlink which is the primary key of a specific record in my SQL database table, it will show the records with the use of textbox or label.

so you want hyperlink on your gridview. and when you click it should be redirect to other page.
after auto generate column false. Add a template filed in your gridview. This will you get from click on smart tag of grid. gor to Edit Column. And ther is available filed add one Template field.
After adding field go to the Edit Tamplate of gridview and add a hyperlink at ther in Itemtamplate.
after adding hyperlink bind the hyperlink with text and navigationUrl.
for e.g. you can see this in source code

<asp:HyperLink ID="HyperLink2" runat="server" Font-Bold="True" ForeColor="Red" Text='<%# Eval("Title", "{0}") %>'
                                                         NavigateUrl='<%# "~/Default.aspx?id=" & Container.DataItem("TitleID") %>' Width="306px"></asp:HyperLink>

it means hyperlink shows the name of the link and it will navigate based on the link Id number. or if you daon't want that Id then simply write your url i.e. NavigateUrl=""~/Default.aspx".
both will working. if problem is solved mark thread as solved.

commented: thanks, i'll try this +1

You can also do the same thing in RawDataBound Event of GridView. In the event, you just need to find the hyperlink column by it's ID in like below :

DataRowView rowView = (DataRowView)e.Row.DataItem;
Hyperlink hLink = e.Row.FindControl("id of hyperlink");
hLink.Text =
hLink.NavigateURL = "test.aspx?empid=" + rowView["emp_id"].ToString();

Now on the test.aspx page, just retrieve query string and pass it in select query to pull all the data related to particular id.

hope it will help you :-)

I have a pair of questions.. I am quite new to this gridview

in asp.net using C#.. I have used the following code to bind the sql database table from my gridview.

SqlDataAdapter da = new SqlDataAdapter("select customerid, customername from table",con);
ds.Clear();
da.Fill(ds);
gridview.datasource=ds;
gridview.databind();

And set the autogenerate columns property to false then add a databound with a datafield that pertains to a column of my table.

1.) How to make the rows of a specific column to be hyperlink. I believe it goes something like <asp:Hyperlink>.

2.) After making the rows of a column to be hyperlink, how could I redirect the link to its corresponding page? What I mean is, if I click a hyperlink which is the primary key of a specific record in my SQL database table, it will show the records with the use of textbox or label.

i'll try this tomorrow. thanks!

Hi..

I had same problem. for its solution you can refer this following code, I think it will help you.

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
    {
       if (e.Row.RowType == DataControlRowType.DataRow)
              {           
     HiddenField hdnField1 = 
HiddenField)e.Row.Cell[i].FindControl("HdnId")).Text;//Have hidden field inside grid view with Id "HdnId"

   HyperLink hlname1 = ((HyperLink)e.Row.Cell[i].FindControl("hl")).Text; //Have Hyperlink inside grid view with Id "hl"
                
                 hlname1.NavigateUrl = "URL"+"?QueryStringKey="+ hdnField1.Value //Replace "URL" with your full URL and "QueryStringKey" with you Key Value.
            }

    }

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.