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 行 https://stackoverflow.com/questions/5170261/gridview-row-in-edit-mode
解决方案:
读完这篇文章后:Gridview 行编辑 - 动态绑定到 DropDownList https://stackoverflow.com/questions/833490/asp-net-3-5-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";
}
}
您应该在数据绑定之前在网格中设置 dataItemIndex。您可以在 RowEditing 事件中执行此操作,
如本例所示:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx
问候,
斯特凡诺
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)