开发者

radio button, set first item as selected

i have a page built in asp.net c#. it holds 开发者_StackOverflow中文版a list of radio buttons on the left side and when a user selects one of the buttons, a content window on the right displays data associated to the button. i would like to set the "selectedindex=0" so on page load the user sees the content of the first radio button.

In my code behind, if i set radioButtonList1.SelectedIndex = 0 within the radio list databind method, the user will see the first radio selection on page load. But the content associated with pre selected radio button does not display. What do i need to include in my content viewer's databinding method do make this happen. Thanks!

-------- code behind

public partial class test_123 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {

      radioButtonList1.SelectedIndex = 0


    }
    protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
    {
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}


Try calling ListBox1_SelectedIndexChanged() explicitly after you set the SelectedIndex to 0 on page load.

protected void Page_Load(object sender, EventArgs e)
{
    if (Page.IsPostBack)
        return;

    radioButtonList1.SelectedIndex = 0;
    ListBox1_SelectedIndexChanged(null, null);
}

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    LoadContent(ListBox1.SelectedIndex);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜