Has a developer you need to know the different ways of doing the same thing.
For Example Updating a Row in a Gridview of ASP.Net with in the Gridview.
- You could do by RowUpdating event of Gridview or
- Use RowCommand Event.
In any of the methods you need to get the selected row. In RowUpdating event of Gridview you can get that by simply using the command arguments such as 'e'. Using RowIndex you will get the selected row.
On the other hand what about when we use Row Command Event. Here how its done.
Here we are taking a button which will edit the row. When we press this button it make the controls editable and after when we click on update the selected row should be updated.
to get the Selected Row we Use CommmandArgument of the button as follows.This is .aspx page
<asp:Button ID="btnEdit" runat="server" CausesValidation="false" CommandName="EditRow"
Text="Edit" AccessKey="W" AccessControlId="btnEdit" CommandArgument='<%#DataBinder.Eval(Container, "RowIndex")%>' />
So in cs page or code behind page you can get this bu following code
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "EditRow")
{
try
{
int i = int.Parse(e.CommandArgument.ToString());
.......
.......
}
}
}
Now you get the SelectedRow !