C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET GridView »

How to get a seelcted row from gridview on button click uisng row command event in c#


Posted Date: 07 Oct 2008    Resource Type: Code Snippets    Category: ASP.NET GridView
Author: DeepakMember Level: Bronze    
Rating: 1 out of 5Points: 7



This small code will help some body for fetch the data from different controls in a gridview.
I have created a gridview and bind it with 3 data bound column(id,name and age) from sql datasource . i have added a button field (its not a template column) with button type as last column .so when i click the button aganist on each row the other column values on corrosponding row should be fetched.
I have Mapped the follwing procedure (MyGridview_RowCommand)to RowCommand Event through property box of grid view.
For button field (last column of gridview)i have given the name "FindValue" as CommandName for conditional running of code at runtime.


protected void MyGridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.ToString() == "FindValue")
{
GridViewRow row = ((GridView)e.CommandSource).Rows[Convert.ToInt32(e.CommandArgument)];
string id = ((Label)(row.FindControl("label1"))).Text;
string name = ((Label)(row.FindControl("Label2"))).Text;

}
}









Responses

Author: mike    04 Nov 2008Member Level: Bronze   Points : 0
Excellent code snippet. Thanks for taking the time to post!


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Gridview  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Sorting in the Gridview
Previous Resource: Custom Paging using Object Data Source
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET GridView


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use