473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to add listitem in dropdownlist using C# behind code.

Hi All,

Im using VWD 2008 (c#), I have a question here.

Im having a dropdownlist like this:

Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="True" 
  2.                                 Height="24px" onselectedindexchanged="DropDownList2_SelectedIndexChanged" 
  3.                                 style="font-family: 'Arial'; font-size: small;" Width="170px">
  4.        <asp:ListItem></asp:ListItem>
  5.        <asp:ListItem Value="TMS">TMS</asp:ListItem>
  6.        <asp:ListItem Value="FMS">FMS</asp:ListItem>
  7.        <asp:ListItem Value="CPCS">CPCS</asp:ListItem>
  8.        <asp:ListItem Value="PC Issue">PC Issue</asp:ListItem>
  9.        <asp:ListItem Value="Printer Issue">Printer Issue</asp:ListItem>
  10.        <asp:ListItem Value="Folder Access">Folder Access</asp:ListItem>
  11.        <asp:ListItem Value="Internet Issue">Internet Issue</asp:ListItem>
  12.        <asp:ListItem Value="Email Issue">Email Issue</asp:ListItem>
  13.        <asp:ListItem Value="Others">Others(Specify)</asp:ListItem>
  14. </asp:DropDownList>
I want to know how to add listitem in dropdownlist using onclick a button and a text box(for listitems value).

Thanks in advance.

-Meshack
Oct 23 '08 #1
5 37876
hi try this this si in c#
ddlIssue.Items.Add(new ListItem("text", "value"));

Hi All,

Im using VWD 2008 (c#), I have a question here.

Im having a dropdownlist like this:

Expand|Select|Wrap|Line Numbers
  1. <asp:DropDownList ID="ddlIssue" runat="server" AutoPostBack="True" 
  2.                                 Height="24px" onselectedindexchanged="DropDownList2_SelectedIndexChanged" 
  3.                                 style="font-family: 'Arial'; font-size: small;" Width="170px">
  4.        <asp:ListItem></asp:ListItem>
  5.        <asp:ListItem Value="TMS">TMS</asp:ListItem>
  6.        <asp:ListItem Value="FMS">FMS</asp:ListItem>
  7.        <asp:ListItem Value="CPCS">CPCS</asp:ListItem>
  8.        <asp:ListItem Value="PC Issue">PC Issue</asp:ListItem>
  9.        <asp:ListItem Value="Printer Issue">Printer Issue</asp:ListItem>
  10.        <asp:ListItem Value="Folder Access">Folder Access</asp:ListItem>
  11.        <asp:ListItem Value="Internet Issue">Internet Issue</asp:ListItem>
  12.        <asp:ListItem Value="Email Issue">Email Issue</asp:ListItem>
  13.        <asp:ListItem Value="Others">Others(Specify)</asp:ListItem>
  14. </asp:DropDownList>
I want to know how to add listitem in dropdownlist using onclick a button and a text box(for listitems value).

Thanks in advance.

-Meshack
Oct 23 '08 #2
hi try this this si in c#
ddlIssue.Items.Add(new ListItem("text", "value"));
Hi Vivek,

Thanks for the guidance. It working well. But the thing is I want the listitem added permanently. The one give was temporary. Can you help me with this.

Thanks again.

-Meshack
Oct 24 '08 #3
joedeene
583 512MB
When you say permanently, rather than temporary, do you mean each time the page is refreshed? If so, I think you might have to integrate using a database. If not, what do you mean "only temporary"...

joedeene
Oct 24 '08 #4
When you say permanently, rather than temporary, do you mean each time the page is refreshed? If so, I think you might have to integrate using a database. If not, what do you mean "only temporary"...

joedeene
Hi Joedeene,

Thanks for your comment. Now i got it. Integrate with a database. Thats great idea. I didnt even think it. Thanks again.

-Meshack
Oct 24 '08 #5
Hi All,

I have another question here. I have done with the integration with database.
Now my ddlLevel dropdownlist have integration with 2 tables. First is ddlUserlevel table for list down the itemlist. Another is Staff table which is here it retrieve data from the table to dropdownlist.

The problem is when I try to view the the page where ddlLevel is, it prompt error
that
[HTML]'ddlLevel' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value [/HTML]

The other dropdownlist that im using this same above method got no problem. To solve the problem I went into table staff and change the data to UPPER CASE. Now it not prompt any error. But the question is how to solve the error without get to database to change data's CASE.

Thanks in advance,

-Meshack
Oct 24 '08 #6

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

Similar topics

10
by: Fabio Negri Cicotti [MCP] | last post by:
Sorry for my silly question... in the same way we can define in a DropDownList the "ValueMember" and "Display Member" when we bind a DatasSource, how could I do it using a hard-code fixed...
6
by: Sebi | last post by:
Hello all, I'm thinking about overwriting the ListItem, so it can contain x additional values (not only one). Has anybody ever tried this? Has someone got an example (C#)? Can DropDownList...
2
by: Mad Scientist Jr | last post by:
I am populating a dropdownlist from SQL. The query returns the correct values (and no NULLs in any fields). The listitem.value is populated with an int ID field, and listitem.text with a varchar...
3
by: Nathan Sokalski | last post by:
I want to change the background color, font attributes, etc. of the choices in my DropDownLists. When writing them using HTML SELECT and OPTION tags, I can do something like the following: ...
8
by: barry | last post by:
Have tried a number of things including space(n) in front of the string but when the DropDownList is shown the spaces have apparently been trimmed. Is this something that would have to be done in a...
5
by: Mark Rae | last post by:
Hi, Has the <asp:DropDownList> - <asp:ListItem> functionality changed in v2? In v1.1, the following works as expected: <asp:DropDownList ID="cmbStatus" Runat=server EnableViewState=False>...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
3
by: Merennulli | last post by:
My problem child: <asp:dropdownlist id="ddlLimit" tabIndex="6" runat="server" EnableViewState="False" CssClass="query"> <asp:ListItem Value="100" Selected="True">100</asp:ListItem>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.