473,715 Members | 2,266 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

The DropDownList Control can not refresh problem!!

JimWu
14 New Member
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 5698
shweta123
692 Recognized Expert Contributor
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.

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 New Member
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.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.
Sep 19 '07 #3

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

Similar topics

4
7458
by: theo | last post by:
Program flow...load file,then extract the xml text tags from the file,then the number of Xml tags retrieved from the file determines the number of dropdownlist controls instanciated in the placeholder,the user selects the required tags from the dropdownlists (if 5 Xml tags,then 5 dropdownlists each containing 5 xml tags) and now the btnSave button is selected which extracts the user selection form the dropdownlists.
2
9694
by: DesignerX | last post by:
I am being sent an ArrayList of ListItems. I can bind to a dropdownlist control using: oDropDownList.DataSource = oArrayList This works but when the dropdownlist is rendered both the select box value and the text are the same (The ListItem.Text), How do I get the ListItem.Text to render as the text and the ListItem.Value to be the html select option 'value'?
2
2048
by: Ali | last post by:
I am adding a DropDownList control to my DataGrid footer template. I load my DropDownList using a function that returns an arrayList. I can see all my items in the DropDownList, but when I select an item from the list, I am unable to trap the DropDownList SelectedIndexChanged event. This is a snippet of my DataGrid: <asp:TemplateColumn> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "State") %>
0
1039
by: jonathanyan | last post by:
Hi all: I am dynamically creating two dropdownlist controls in a user control, the data of the second dropdownlist control depends on the selected value of the first dropdownlist control, the first dropdownlist control has a post back event, in which it will bind the data to the second control based on the selected value of the first control. Both auto postback and data binding work fine, but when I tried selected a value in the second...
6
16609
by: Oscar | last post by:
I want to add items to a dropdownlist control within a Javascript eventhandler. This is what I code : var dd = document.getElementById("DropDownList1"); dd.Items.Add("1990"); dd.Items.Add("1991"); dd.Items.Add("1992");
2
16093
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine in my asp tag as shown here: <asp:DropDownList id="ddlTo" runat="server"
2
2053
by: jack | last post by:
Hi all im trying to use DropDownList control in GridView The senerio is like the <ItemTemplateControl is a Label control and when click on edit control DropDownList should be the <EditItemTemplatecontrol I want to get the selected value from the dropdownlist control of the selected row from the gridview. Im pretty confused about these and tried a lot but not able to do this.
7
17439
by: =?Utf-8?B?UmVraGE=?= | last post by:
Hi, I am trying to change the font color for the items in a dropdownlist control at run time using ASP.NET 2.0. DropDownList1.Items.Attributes.Add("style", "color:red"); But when I run the application, I don't see any color change. I am using Visual Studio 2005, ASP.NEt 2.0.
0
976
by: henrychong | last post by:
Can someone help me. I want to find a dropdownlist control in a datagrid (named dgDestinations) and i want to make the dropdownlist visible in Page_load. How can i access the control in Page_load? It works if i find a control in an itemcommand, but not in Page_load or other functions. Here's the code: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim ddlbox As...
1
1262
by: =?Utf-8?B?aUhhdkFRdWVzdGlvbg==?= | last post by:
I have a dropdownlist of width 100px in a webform. When I hit the control, I gets the list of items that I populated in a pageload. My problem is that the items in my dropdown are more in length then a dropdownlist control I want to keep the drop down the same length as it is and when I hit the dropdownlist i should let the user to see the full length in an item. I would also want to display only 5 items when I hit the drop down...
0
8819
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8717
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9099
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9041
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6645
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5966
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4475
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4737
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.