0

I am looking for this over the internet but I am not getting any suitable answers. Here is my problem:

I have a web user control which has the following three controls

<asp:RadioButtonList ID="RadioButtonList1" runat="server"     AutoPostBack="true" 
CssClass="radioButton" RepeatDirection="Horizontal" RepeatLayout="Flow" 
onselectedindexchanged="RadioButtonList1_SelectedIndexChanged" >
    <asp:ListItem Value="UET111">Use Existing</asp:ListItem>
    <asp:ListItem Value="CNT111">Create New</asp:ListItem>
</asp:RadioButtonList>

<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
<asp:TextBox ID="TextBox1" runat="server" C></asp:TextBox>

It's code behind

 protected void Page_Load(object sender, EventArgs e)
    {
        DropDownList1.Visible = false;
        TextBox1.Visible = false;
    }

    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (RadioButtonList1.SelectedItem.Value == "UET")
        {
            DropDownList1.Visible = true;
            TextBox1.Visible = false;
        }
        else if (RadioButtonList1.SelectedItem.Value == "CNT")
        {
            DropDownList1.Visible = false;
            TextBox1.Visible = true;
        }
    }

Now my question- Actually I am using this web control 5 times on the same aspx page. The problem is I want to fill the dropdown list from aspx page and each dropdown will have different data(as I have 5 user control).

Is it possible to do that? Please help me with these and let me know if anyone knows a better way of doing this.

4

1 回答 1

1

Create a public function in your user control that lets you send in a DataSource for the dropdown list to populate from, and if you want bind as well.

public BindDropdownDataSource(DataSet dataSource)
{
    DropDownList1.DataSource = dataSource;
    DropDownList1.DataBind();
}
于 2015-09-02T20:32:10.513 回答