2012-09-22 57 views
0

我有一個RadioButtonList和一個ListBox。我已經綁定了RadioButtonList到數據庫。 因此,在選擇RadioButtonList中的項目後,我想要將一些數據檢索到ListBox。我曾嘗試的代碼是:在RadioButtonList中選擇一個項目,如何從asp.net中的數據庫獲取一個ListBox項目列表c#

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(); 
} 

我面對這裏是在選擇項目的問題,整個面板中,我已經把我的兩個RadioButtonListListBox去無形。

請幫助...... !!謝謝...!!

+0

你能不能展示你如何在你的aspx頁面中定義你的RadioButtonList1和ListBox1? – avi

+0

我編輯了我的問題。 –

+0

你的代碼似乎確定...你可以顯示該面板的代碼嗎?該小組如何定義這2個項目?或者它們是動態創建的? – avi

回答

1

首先,改變Page_Load方法爲:

protected void Page_Load(object sender, EventArgs e)¨ 
{ 
    if (!Page.IsPostBack) 
    { 
      RadioFill(); 
    } 
} 

如果不是比你的* .aspx文件郵編幫助。

備註:方法RadioButtonList1_SelectedIndexChanged(對象發件人,EventArgs e), 沒有基於單選按鈕列表選擇值的選擇。

+0

謝謝。它的工作 –

相關問題