What are the different ways Get the id of Particular row in Grid View? [Resolved]

Posted by Amatya under ASP.NET on 5/16/2015 | Points: 10 | Views : 310 | Status : [Member] | Replies : 2
In how many types i Can get the unique id of the row in Grid View?

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks



Responses

Posted by: Rojalin on: 10/13/2015 [Member] Starter | Points: 50

Up
0
Down

Resolved
there are many way to have particular row id od gridview:
Way 1:
Using Select for each row OnRowDataBound and OnSelectedIndexChanged you can have the selected rowIndex:
protected void OnSelectedIndexChanged(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowIndex == GridView1.SelectedIndex)
{
int index = GridView1.SelectedIndex ;
break;
}
}
}

For more refer http://www.aspsnippets.com/Articles/Selecting-GridView-Row-by-clicking-anywhere-on-the-Row.aspx

Way 2:
OnButtonClick of Gridview Specific Row:
protected void Button1_Click(object sender, EventArgs e)
{
int index = ((GridViewRow)((sender as Button)).NamingContainer).RowIndex;
}


Way 3:
OnRowCommand :
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow gvRow = GridView1.Rows[index];
}


Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Amatya on: 2/3/2016 [Member] Silver | Points: 25

Up
0
Down
nice man .. i Got . Thanks

Feel free to share informations 9731764134
mail Id ' adityagupta200@gmail.com
Thanks

Amatya, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response