If you want to click row in gridview and then call sever side function , for example, change the color of selected row , below code is for your reference :
The SelectedIndexChanged event of GridView will only fire once you set the ShowSelectButton command field or by setting the AutoGenerateSelect button to True in your GridView. Here's a quick example:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
TextBox1.Text = GridView1.SelectedRow.Cells[1].Text;
//If accessing TemplateField column then you can use FindControl method
//Can your function here
}
Vincent Maverick Durano
Microsoft MVP, CodeProject MVP, C# Corner MVP
Blog | Twitter | Linkedin
Member
239 Points
1074 Posts
call function on grid view row
Jun 15, 2016 05:58 AM|Capricon User|LINK
i try to call function when i click on grid view row.. there is multiple rows in grid view when user click on row then i call function
i try this
when i click on row nothing happens
how i do this
All-Star
191723 Points
20951 Posts
ASPInsiders
Moderator
MVP
Re: call function on grid view row
Jun 15, 2016 06:14 AM|XIII|LINK
Hi,
it's been quite some time I did something with this particular control but the RowDataBound event is handled whenever a row gets databound to the grid. For catching the selected row you'll need another event to handle that. Take a look at the example at https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedrow(v=vs.110).aspx on how to grab the selected row and act accordingly.
Grz, Kris.
Working with Azure, chatbots, ASP.NET MVC, Web API, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
Member
239 Points
1074 Posts
Re: call function on grid view row
Jun 15, 2016 06:20 AM|Capricon User|LINK
ok now i try this
but when i click on row nothing happens
All-Star
191723 Points
20951 Posts
ASPInsiders
Moderator
MVP
Re: call function on grid view row
Jun 15, 2016 06:55 AM|XIII|LINK
Hi,
as I didn't see what you have for markup, check that you set the onselectedindexchanged="GridView1_SelectedIndexChanged" as well.
Also place a breakpoint in this event and see if it gets hit.
Grz, Kris.
Working with Azure, chatbots, ASP.NET MVC, Web API, EF, MS SQL, ...
Keep the forums clean: report to the moderation team!
All-Star
18815 Points
3831 Posts
Re: call function on grid view row
Jun 15, 2016 07:19 AM|Nan Yu|LINK
Hi ,
If you want to click row in gridview and then call sever side function , for example, change the color of selected row , below code is for your reference :
Code behind :
You could also use jquery to find selected row :
http://www.aspsnippets.com/Articles/Change-Gridview-Row-Color-OnClick-without-PostBack-in-ASPNet.aspx
Best Regards,
Nan Yu
All-Star
102952 Points
19469 Posts
MVP
Re: call function on grid view row
Jun 16, 2016 05:44 PM|vinz|LINK
The SelectedIndexChanged event of GridView will only fire once you set the ShowSelectButton command field or by setting the AutoGenerateSelect button to True in your GridView. Here's a quick example:
then at SelectedIndexChanged event you can do:
Microsoft MVP, CodeProject MVP, C# Corner MVP
Blog | Twitter | Linkedin