c# - GridView 取一行

标签 c# asp.net

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 row in edit mode

解决方案: 阅读此文后: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";
        }
    }

最佳答案

您应该在数据绑定(bind)之前在网格中设置dataItemIndex。你可以在 RowEditing 事件中做到这一点, 如本例所示:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowediting.aspx

问候, 斯特凡诺

关于c# - GridView 取一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5169538/

相关文章:

c# - 为什么 PDFTron PDFViewCtrl.Update() 抛出 AccessViolationException

c# - 延迟任务,超过延迟时间则返回空值

c# - 将所有 treeView 父级和子级复制到另一个 treeView c# WinForms

asp.net - 从 ascx 找到对 aspx 的控制

c# - 删除从客户端发送的值列表

c# - 测试事件驱动的行为

c# - 在 Visual Studio 2017 中的 'web site' 中设置 C# 7

javascript - 从javascript中的下拉列表中获取选定的索引

javascript - 为什么我不能使用 jquery 显示/隐藏 Html TR?

c# - iOS 设计具有可定制内容的 UITableViewCell