GridView排了一排
net 4和c#。
我有一个GridView,我想在我的代码中编辑模式中取一行并找到一个控件。
在这里我的代码,但不起作用,它只需要GridView的第一行。
有任何想法吗?
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; }
我的代码示例: GridView在编辑模式下行
解决方案:阅读之后: Gridview行编辑 – 动态绑定到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"; } }
编辑:添加了DataRow
检查
if (e.Row.RowType == DataControlRowType.DataRow && e.Row.RowState == DataControlRowState.Edit)
代替
if (e.RowState == DataControlRowState.Edit)
你应该在datatabind之前在网格中设置EditItemIndex。 您可以在RowEditing事件中执行此操作,如下例所示:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx
此致,斯特凡诺