在RadioButtonList中选择一个项目,如何从asp.net c#中从数据库获取列表项。

时间:2021-07-27 03:06:01

I have a RadioButtonList and a ListBox. I have bound RadioButtonList to database. Therefore upon selecting an item in the RadioButtonList, I want to retrieve some data into the ListBox. The code I have tried is :

我有一个收音机按钮和一个列表框。我已经把RadioButtonList绑定到数据库。因此,在选择RadioButtonList中的项时,我想要在列表框中检索一些数据。我试过的代码是:

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

The issue I am facing here is upon selecting an item, the whole panel in which I have placed both my RadioButtonList and ListBox goes invisible.

我在这里面临的问题是在选择一个项目时,我放置我的RadioButtonList和ListBox的整个面板都是不可见的。

Kindly help...!! Thankyou...!!

请帮助! !谢谢! !

1 个解决方案

#1


1  

First, change Page_Load method as:

首先,将Page_Load方法更改为:

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

If it not help than post code from your *.aspx file.

如果它没有帮助你的代码从你的*。aspx文件。

Remark: The method RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e), there is not selecting based on radio button list selected value.

备注:方法RadioButtonList1_SelectedIndexChanged(对象发送方,EventArgs e),没有选择基于选择的值的单选按钮。

#1


1  

First, change Page_Load method as:

首先,将Page_Load方法更改为:

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

If it not help than post code from your *.aspx file.

如果它没有帮助你的代码从你的*。aspx文件。

Remark: The method RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e), there is not selecting based on radio button list selected value.

备注:方法RadioButtonList1_SelectedIndexChanged(对象发送方,EventArgs e),没有选择基于选择的值的单选按钮。