![](/img/trans.png)
[英]How to load items into dropdownlist after selecting item from another dropdownlist in asp.net c#
[英]Selecting an item in the RadioButtonList, how to get a list of items to a ListBox from database in asp.net c#
我有一個RadioButtonList
和一個ListBox
。 我已將RadioButtonList
綁定到數據庫。 因此,在RadioButtonList
選擇一個項目后,我想將一些數據檢索到ListBox
。 我試過的代碼是:
protected void Page_Load(object sender, EventArgs e)
{
RadioFill();
}
public void RadioFill()
{
SqlDataAdapter mydata = new SqlDataAdapter("SELECT DISTINCT Param_Name FROM Parameter_Value_Master", con);
DataSet dset = new DataSet();
mydata.Fill(dset, "Table");
RadioButtonList1.Items.Clear();
RadioButtonList1.DataSource = dset.Tables[0];
RadioButtonList1.DataTextField = dset.Tables[0].Columns["Param_Name"].ColumnName;
RadioButtonList1.DataBind();
}
protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlDataAdapter mydata = new SqlDataAdapter("SELECT Value_Option FROM Parameter_Value_Master", con);
DataSet dset = new DataSet();
mydata.Fill(dset, "Table");
ListBox1.Items.Clear();
ListBox1.DataSource = dset.Tables[0];
ListBox1.DataTextField = dset.Tables[0].Columns["Value_Option"].ColumnName;
ListBox1.DataBind();
}
我在這里面臨的問題是選擇一個項目時,我放置了RadioButtonList
和ListBox
的整個面板都不可見。
請幫助...! 謝謝...!!
首先,將Page_Load方法更改為:
protected void Page_Load(object sender, EventArgs e)¨
{
if (!Page.IsPostBack)
{
RadioFill();
}
}
如果這不是幫助* .aspx文件中的代碼。
備注:方法RadioButtonList1_SelectedIndexChanged(object sender,EventArgs e),沒有基於單選按鈕列表選擇的選定值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.