How can i get row index of the grid view whose child control is doing post back. I know the way of getting control causing post back and finding its parent container which returns grid view row and then find its index. I want this in a RowDataBound event to check selectedrow index and formatting the same. Is there any other property or settings which directly emits selected index of the grid view on any child control post back
Edit:
For example if there is a dropdownlist in a row and there are certain rows in a gridview. Then i want gridview rowindex where postback happens due to that dropdowlist in the gridview row.
As the object suggests (GridViewUpdateEventArgs) 'e' stands for the events relating to the update of a grid view. You can get similar method signatures that relate to other events such as deletions etc. The 'RowIndex' relates to the index of the row on which this event was fired.
The RowCommand event is raised when a button is clicked in the GridView control. This enables you to provide an event-handling method that performs a custom routine whenever this event occurs.
You can get the index of the row in RowDataBound
via the RowIndex
property:
protected void gridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int index = e.Row.RowIndex;
}
}
You can get the index of any child control in a GridView via
childControl.NamingContainer
=> GridViewRow
=> RowIndex
for example in a DropDownList.SelectedIndexChanged
event:
protected void DropDownList1_SelectedIndexChanged(Object sender, EventArgs e)
{
DropDownList ddl = (DropDownList) sender;
GridViewRow row = (GridViewRow) ddl.NamingContainer;
int index = row.RowIndex;
}
Finally: since you've mentioned " to check selectedrow index", if you're actually looking for the selected row index of the GridView
itself, there's a property just for this:
GridView.SelectedIndex
PropertyIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With