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();
}
我的表中有项目,一旦我在Dropdownlist
中选择任何值,我需要在RadioButtonList
中显示我的项目。
我还可以看到ds.Tables[0]
行中的项目,但我无法将它们绑定到Dropdownlist
。
答案 0 :(得分:0)
con.Open();
if (RadioButtonList1.SelectedIndex == 0)
{
cmd = new SqlCommand("select [Item] from [Veg_Items]", con);
SqlDataReader dr = cmd.ExecuteReader();
List<Object> lt = new List<Object>();
if (dr.HasRows)
{
while (dr.Read())
{
lt.Add(dr["Item"].ToString());
}
}
DropDownList1.DataSource = lt;
DropDownList1.DataBind();
}
else if (RadioButtonList1.SelectedIndex == 1)
{
cmd = new SqlCommand("select [Item] from [NonVeg_Items]", con);
SqlDataReader dr = cmd.ExecuteReader();
List<Object> lt = new List<Object>();
if (dr.HasRows)
{
while (dr.Read())
{
lt.Add(dr["Item"].ToString());
}
}
DropDownList1.DataSource = lt;
DropDownList1.DataBind();
}
con.Close();