我试图找到我的问题的解决方案,我在gridview中的下拉列表没有绑定,有没有办法覆盖这个?
这是我得到的错误:
数据绑定方法(如Eval(),XPath()和Bind())只能在数据绑定控件的上下文中使用。
感谢
<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>
答案 0 :(得分:1)
您必须在RowDataBound处理程序中绑定DropDownList。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Bind DropDownList here
}
}