Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding an item to a DropDownList which is connected to a SQLDataSource 1

Status
Not open for further replies.

technisup

Programmer
Sep 28, 2007
41
US
Hi, how can i add a new item manually to a dropdownlist which is connected to a SQLDataSource?

This is my current code:
Code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataGrupo" DataTextField="Descripcion"
                        DataValueField="IdGrupo" Style="position: relative">
                        <asp:ListItem Selected="True" Value="0">:: Seleccione ::</asp:ListItem>
                    </asp:DropDownList><asp:SqlDataSource ID="SqlDataGrupo" runat="server" ConnectionString="<%$ ConnectionStrings:SIPConnectionString %>"
                        SelectCommand="SELECT * FROM [Grupo]"></asp:SqlDataSource>
But is not displaying the new item ":: Seleccione ::" along with the other items extracted from the table.
 
couple different options.
Code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataGrupo" DataTextField="Descripcion" DataValueField="IdGrupo" Style="position: relative" AppendDataBoundItems="true">
   <asp:ListItem Selected="True" Value="0">:: Seleccione ::</asp:ListItem>
 </asp:DropDownList>
or
Code:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataGrupo" DataTextField="Descripcion" DataValueField="IdGrupo" Style="position: relative" >
 </asp:DropDownList>

//code behind
DropDownList1.DataBind();
DropDownList1.Items.Insert(0, new ListItem("", "text"));


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top