【问题标题】:How to fill Dropdown list from Database at the time of editing row in gridview in asp.net如何在asp.net的gridview中编辑行时从数据库中填充下拉列表
【发布时间】:2014-06-07 16:02:36
【问题描述】:

我想在编辑行时从数据库的下拉列表中显示数据。下拉列表放在<EditItemTemplate>代码文件中如何访问这个下拉列表..

  <asp:TemplateField ItemStyle-Width="30px" HeaderText="Group of Broker">
        <itemtemplate>
            <asp:Label ID="lblGroupofBroker" runat="server" Text='<%# Eval("groupofbroker")%>'></asp:Label>
        </itemtemplate>
        <edititemtemplate>
            <asp:DropDownList ID="ddlGroupofBroker" runat="server" DataTextField='<%# Eval("groupofbroker") %>'> </asp:DropDownList>
        </edititemtemplate>
        <itemstyle width="30px" />
        <footertemplate>
            <asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>`
        </footertemplate>
    </asp:TemplateField>

请帮助我如何访问代码文件中的此下拉列表以从数据库中填充数据

【问题讨论】:

    标签: c# asp.net gridview


    【解决方案1】:

    你需要处理gridview_RowEditing事件

    protected void gridview_RowEditing(object sender, GridViewEditEventArgs e)
        {
        GridViewRow row = gvAllClients.Rows[e.NewEditIndex];
    
           // Change the row state
        DropDownList ddlDataType = (DropDownList)(row.FindControl("ddlDataTypeAll"));
         //ddlDataType.DataSource = <datasocurce>;
         //ddlDataType.DataBind(); 
    
    
        }
    

    【讨论】:

    • System.Web.dll 中发生“System.InvalidOperationException”类型的异常,但未在用户代码中处理其他信息:数据绑定方法,例如 Eval()、XPath() 和 Bind()只能在数据绑定控件的上下文中使用。
    • 我遇到了同样的事情。有什么解决办法吗??
    猜你喜欢
    • 2011-11-21
    • 1970-01-01
    • 2017-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 2021-05-19
    • 2011-08-31
    相关资源
    最近更新 更多