Reputation: 73918
net 4 and c#.
I have a GridView, I would like take a Row when in Edit Mode in my code and find a control.
Here my code, but does not work, it takes only the first row for the GridView.
Any ideas?
protected void uxManageSlotsDisplayer_RowDataBound(object sender, GridViewRowEventArgs e)
{
switch (e.Row.RowType)
{
case DataControlRowType.DataRow:
// Take Row in Edit Mode DOES NOT WORK PROEPRLY
if (e.RowState == DataControlRowState.Edit)
{
Label myTest = (Label)e.Row.FindControl("uxTest");
}
break;
}
MY CODE EXAMPLES: GridView row in edit mode
SOLUTIONS: After reading this: Gridview row editing - dynamic binding to a DropDownList
protected void uxList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow &&
(e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit)
{
// Here you will get the Control you need like:
Label dl = (Label)e.Row.FindControl("uxLblTest");
dl.Text = "xxxxxxxxxxxxx";
}
}
Upvotes: 2
Views: 1826
Reputation: 4224
you shoud set EditItemIndex in the grid before datatabind. you can do it in RowEditing event, as in this example:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx
Regards, Stefano
Upvotes: 1
Reputation: 108957
Edit:
Added check for DataRow
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit)
instead of
if (e.RowState == DataControlRowState.Edit)
Upvotes: 0