我意识到您可以使用SqlDataSource在gridview中轻松设置一个下拉列表,但是仅包含listitems的有限列表又如何呢?没有数据源,将“绑定”放入所选值似乎不起作用。这是到目前为止我所学的一个例子。
<EditItemTemplate>
<asp:DropDownList ID="Fund" runat="server" SelectedValue='<%# Bind("Fund") %>' >
<asp:ListItem Value="">---</asp:ListItem>
<asp:ListItem Value="Test1">Test</asp:ListItem>
<asp:ListItem Value="Test2">Test2</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
似乎有一个愚蠢的小问题,以至于我要在数据库中创建一个静态的10行表。
最佳答案
尝试这个:
Dictionary<string, string> items= new Dictionary<string, string>();
items.Add("-1","-Select-");
items.Add("Test1", "Test1");
items.Add("Test2", "Test2");
ddl.DataSource = items;
ddl.DataValueField = "Key";
ddl.DataTextField = "Value";
ddl.DataBind();
关于c# - 在Gridview中绑定(bind)没有SqlDataSource的DropDownList,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11347343/