C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




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

Posted By: Deepak       Member Level: Bronze
Rating:     Points: 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  
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!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

accuconference

Contact Us    Privacy Policy    Terms Of Use