user84786
user84786

Reputation: 631

Asp.Net Gridview Buttonfield get Row Data

I have a Gridview which is binded to a datatable that I created. The data in the table is ever changing.

I added a buttonfield to the Gridview. When clicked I want to send a specific columns value in that row through a link or sent through a function.

How do you go about doing this?

Upvotes: 5

Views: 19274

Answers (2)

user84786
user84786

Reputation: 631

I found out how to do it. You set the commandName property to whatever you want to call it inside the properties.

Then if you double click on the button after creating it in design view, it should pop up a function in the code behind page. You can then access the row by doing the following.

protected void gvUsers_RowCommand(object sender, GridViewCommandEventArgs e) {

 int rowNum = int.Parse(e.CommandArgument.ToString());

}

from there you can use the row number to access specific column data.

Upvotes: 6

rlb.usa
rlb.usa

Reputation: 15043

Here's a decent example from MSDN: http://msdn.microsoft.com/en-us/library/bb907626.aspx

Upvotes: 3

Related Questions