472,133 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,133 software developers and data experts.

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 5653
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

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.