我有一個下拉列表,它是從一個表 數據爲界,我想從它在頁面加載刪除項目,但問題是沒有從這段代碼發生的事情:如何刪除數據有限頁面加載下拉列表項目?
頁負載:
protected void Page_Load(object sender, EventArgs e)
{
ListItem itemToRemove = DropDownList1.Items.FindByText("compiler"); //just want to remove this value
if (itemToRemove != null)
{
DropDownList1.Items.Remove(itemToRemove);
}
}
**dropdownlist code on aspx page**:
<asp:DropDownList ID="DropDownList1" AppendDataBoundItems="true" runat="server" DataSourceID="SqlDataSource1" DataTextField="qpname" DataValueField="qpname" Height="16px" Width="116px" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True">
<Items>
<asp:ListItem Text="Select" Value="" />
</Items>
</asp:DropDownList>
aspx頁面上SQLDATA源代碼:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:projectConnectionString %>" SelectCommand="SELECT [qpname] FROM [A1_quespapers]"></asp:SqlDataSource>
注:dropdow NLIST是顯示所有有界值,包括價值將被刪除(編譯) - image here
嘗試把你的代碼的IsPostBack – Webruster