Hi,
How to set hyperlink to the primary key column in grid view. Instead of using edit update delete actions in grid view, i wanted to click on primary key column and it should navigate me to the respective pages.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 3, 2013, 8:33 PM EDT
plz provide more details.
sita k41 reputationPosted Sep 3, 2013, 8:45 PM EDT
I got an employee table with columns emp_id, name and sal. Now in the grid view I would like to provide hyperlink to emp_id.If I would like to perform update and delete operations after selecting the hyperlink i.e emp_id i should navigate to update page. To make it simple i don't want to add separate edit or delete actions in the grid view.
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 3, 2013, 9:22 PM EDT
Take a link button in gridview item template. and bind the id to linkbutton text and to command argumet and write command name in that. then write the code in gridview rowcommand to catch the id then pass it to next page.
Ex:
in cs:
protected void gvArea_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "NEdit")
{
int id=Convert.ToInt32(e.CommandArgument.ToString());
Response.Redirect("");//pass the id as query string here to next page
}
}
sita k41 reputationPosted Sep 5, 2013, 1:30 AM EDT
With your code I am able to achieve what I wanted but I am facing errors :
1.I am trying to avoid emp_id in the gridview query since i am binding it in the link button.By doing this way I am having binding issues.
2.If I do select emp_id then I am having two emp_id columns one with link and one without.How to resolve this?
Prasenjit DeyRank #6,279 · 271 reputationPosted Sep 5, 2013, 1:44 AM EDT
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Sep 5, 2013, 4:27 AM EDT