469,331 Members | 1,861 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

The DropDownList Control can not refresh problem!!

JimWu
14
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#.
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         DropDownList1.AutoPostBack = true;
  4.         DropDownList1.Items.Clear();
  5.         DropDownList1.Items.Add(new ListItem("test1","0"));
  6.         DropDownList1.Items.Add(new ListItem("test2", "1"));
  7.     }
  8. protected void Button1_Click(object sender, EventArgs e)
  9. {
  10.         TextBox1.Text = DropDownList1.SelectedItem.Text;
  11.  }
  12. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  13. {
  14.         //DropDownList1.Items.FindByValue();
  15.         DropDownList1.ClearSelection();
  16.         DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
  17.         TextBox1.Text = DropDownList1.SelectedValue;
  18. }
  19.  
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
Sep 17 '07 #1
2 5589
shweta123
692 Expert 512MB
Hi,

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

e.g.

If(page.IsPostBack = False)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("test1","0"));
DropDownList1.Items.Add(new ListItem("test2", "1"));

}

Hope this will help.

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#.
Expand|Select|Wrap|Line Numbers
  1.  protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         DropDownList1.AutoPostBack = true;
  4.         DropDownList1.Items.Clear();
  5.         DropDownList1.Items.Add(new ListItem("test1","0"));
  6.         DropDownList1.Items.Add(new ListItem("test2", "1"));
  7.     }
  8. protected void Button1_Click(object sender, EventArgs e)
  9. {
  10.         TextBox1.Text = DropDownList1.SelectedItem.Text;
  11.  }
  12. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  13. {
  14.         //DropDownList1.Items.FindByValue();
  15.         DropDownList1.ClearSelection();
  16.         DropDownList1.Items.FindByValue(DropDownList1.SelectedValue).Selected = true;
  17.         TextBox1.Text = DropDownList1.SelectedValue;
  18. }
  19.  
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
Sep 17 '07 #2
JimWu
14
Thanks for your kindly answer.

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

Best regards,
Jim

Hi,

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

e.g.

If(page.IsPostBack = False)
{
DropDownList1.Items.Clear();
DropDownList1.Items.Add(new ListItem("test1","0"));
DropDownList1.Items.Add(new ListItem("test2", "1"));

}

Hope this will help.
Sep 19 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by DesignerX | last post: by
reply views Thread by jonathanyan | last post: by
7 posts views Thread by =?Utf-8?B?UmVraGE=?= | last post: by
1 post views Thread by =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by Purva khokhar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.