简体   繁体   English

下拉列表的GridView绑定问题

[英]gridview binding problems with dropdownlist

im trying to find a solution to my problem, my dropdownlist in the gridview is not binding, is there any way to override this? 即时通讯试图找到我的问题的解决方案,我在网格视图中的下拉列表没有绑定,有什么办法可以覆盖此?

this is the error i am getting: 这是我得到的错误:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. 诸如Eval(),XPath()和Bind()之类的数据绑定方法只能在数据绑定控件的上下文中使用。

thanks 谢谢

   <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
                DataSourceID="SqlDataSource22" EnableModelValidation="True" ForeColor="#333333"
                Width="2400px" DataKeyNames="KeyFeatureID">
    <AlternatingRowStyle BackColor="White" ForeColor="#284775" HorizontalAlign="Center"
                    VerticalAlign="Middle" />
    <Columns>
         <asp:TemplateField HeaderText="KeyFeatureID" SortExpression="KeyFeatureID" Visible="False">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("KeyFeatureID") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Bind("KeyFeatureID") %>'></asp:Label>
            </ItemTemplate>
            <HeaderStyle Width="60px" />
         </asp:TemplateField>
         <asp:TemplateField HeaderText="Category">
            <EditItemTemplate>
                <asp:DropDownList ID="DDlL" runat="server" EnableViewState="False" Style="font-size: x-small"
                                Width="200px" AppendDataBoundItems="True" DataSourceID="SqlDataSource11104" DataTextField="Category"
                                DataValueField="Category" SelectedValue='<%# Bind("Category") %>'>
                    <asp:ListItem>Category</asp:ListItem>
                </asp:DropDownList>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:Label ID="Label3" runat="server" Text='<%# Bind("Category") %>'></asp:Label>
            </ItemTemplate>
         </asp:TemplateField>
    </Columns>
   </asp:GridView>

You have to bind your DropDownList in RowDataBound handler. 您必须在RowDataBound处理程序中绑定DropDownList。

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            //Bind DropDownList here

        }
     }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM