0
con = new SqlConnection(s);
con.Open();
if (RadioButtonList1.SelectedIndex == 0)
{
cmd = new SqlCommand("select [Item] from Veg_Items", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "[Item]");
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataBind();
}
else if (RadioButtonList1.SelectedIndex == 1)
{
cmd = new SqlCommand("select [Item] from NonVeg_Items", con);
da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds, "[Item]");
DropDownList1.DataSource = ds.Tables[0];
DropDownList1.DataBind();
}
con.Close();
}
我在表格中的項目,我需要一次我選擇RadioButtonList
任何值顯示在Dropdownlist
我的項目。 我也想象了ds.Tables[0]
一行中的項目,但我無法將它們綁定到Dropdownlist
。asp.net下拉列表中的數據綁定在運行時
您的查詢下載數據與否?問題是隻有綁定數據? –
您可以嘗試添加DataTableList的DataTextField和DataValueField到DataTable中的某個列,即DropDownList1.DataTextField =「
它只是獲取該表中的項目。@ mwisnicki –