469,270 Members | 1,117 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

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

Post your reply

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

Similar topics

10 posts views Thread by Fabio Negri Cicotti [MCP] | last post: by
3 posts views Thread by Nathan Sokalski | last post: by
5 posts views Thread by Mark Rae | last post: by
3 posts views Thread by Merennulli | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.