The DropDownList Control can not refresh problem!!

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JimWu
    New Member
    • Aug 2007
    • 14

    The DropDownList Control can not refresh problem!!

    Hi all,
    If this quest is not belong to this forum, I am sorry.
    But I think this question seem to be this forum.
    My problem is while I select a dropdownlist's item and click a button but the result do not show my select dropdownlist item.

    My code as follows using C#.
    Code:
     protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.AutoPostBack = true;
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add(new ListItem("test1","0"));
            DropDownList1.Items.Add(new ListItem("test2", "1"));
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
            TextBox1.Text = DropDownList1.SelectedItem.Text;
     }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
            //DropDownList1.Items.FindByValue();
            DropDownList1.ClearSelection();
            DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
            TextBox1.Text = DropDownList1.SelectedValue;
    }
    Is something wrong about above code, Have anyone tell me what would I do or do any one have go idea for this problem.
    Thanks very much.
    Jim
  • shweta123
    Recognized Expert Contributor
    • Nov 2006
    • 692

    #2
    Hi,

    In the page_load , check the page.postBack before filling the dropdownlist .

    e.g.

    If(page.IsPostB ack = False)
    {
    DropDownList1.I tems.Clear();
    DropDownList1.I tems.Add(new ListItem("test1 ","0"));
    DropDownList1.I tems.Add(new ListItem("test2 ", "1"));

    }

    Hope this will help.

    Originally posted by JimWu
    Hi all,
    If this quest is not belong to this forum, I am sorry.
    But I think this question seem to be this forum.
    My problem is while I select a dropdownlist's item and click a button but the result do not show my select dropdownlist item.

    My code as follows using C#.
    Code:
     protected void Page_Load(object sender, EventArgs e)
        {
            DropDownList1.AutoPostBack = true;
            DropDownList1.Items.Clear();
            DropDownList1.Items.Add(new ListItem("test1","0"));
            DropDownList1.Items.Add(new ListItem("test2", "1"));
        }
    protected void Button1_Click(object sender, EventArgs e)
    {
            TextBox1.Text = DropDownList1.SelectedItem.Text;
     }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
            //DropDownList1.Items.FindByValue();
            DropDownList1.ClearSelection();
            DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
            TextBox1.Text = DropDownList1.SelectedValue;
    }
    Is something wrong about above code, Have anyone tell me what would I do or do any one have go idea for this problem.
    Thanks very much.
    Jim

    Comment

    • JimWu
      New Member
      • Aug 2007
      • 14

      #3
      Thanks for your kindly answer.

      I am already solve my problem and your suggestion is very assistance for me.

      Best regards,
      Jim

      Originally posted by shweta123
      Hi,

      In the page_load , check the page.postBack before filling the dropdownlist .

      e.g.

      If(page.IsPostB ack = False)
      {
      DropDownList1.I tems.Clear();
      DropDownList1.I tems.Add(new ListItem("test1 ","0"));
      DropDownList1.I tems.Add(new ListItem("test2 ", "1"));

      }

      Hope this will help.

      Comment

      Working...