Tuesday, 15 February 2011

sql - How to populate a dropdown list in asp.net from a DB table -



sql - How to populate a dropdown list in asp.net from a DB table -

i'm new asp.net , want populate dropdown list values table created. want populate list 1 of fields- languages in table. think have connected info source correctly, don't know have values list. can come in own values i'd rather have automated.

this have far, i'm guessing there's more linking list info source. help appreciated.

<asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:hbshareindexconnectionstring %>" selectcommand="select * [web_metrics] ([lcid] = @lcid)"> <selectparameters> <asp:querystringparameter name="lcid" querystringfield="lcid" type="int32" /> </selectparameters> </asp:sqldatasource> <asp:label id="label1" runat="server" text="select lcid: " ></asp:label> &nbsp; &nbsp; <asp:dropdownlist id="dropdownlist1" width="150px" runat="server" datasourceid="sqldatasource1" datatextfield="lcid" datavaluefield="lcid"> <asp:listitem>select lcid...</asp:listitem> </asp:dropdownlist>

hi guys, help. got dropdown list populated now, wondering how repeater i'm using display details of lcid person selects? i've seen people talking page.ispostback don't know or if works current setup. need somehow lcid selected , refresh page show details of lcid. have ideas? thanks

your problem you're trying define list items , info source.

if want insert "select item.." option, suggest prepending resultset (getting first union , order by hard depending on fields) or inserting after databinding in code behind:

modification dropdownlist1s attributes:

<asp:dropdownlist id="dropdownlist1" width="150px" runat="server" datasourceid="sqldatasource1" datatextfield="countryname" datavaluefield="lcid" ondatabound="insertchooseitem" />

c#:

protected void insertchooseitem(object sender, eventargs e) { listitem selectoneplease = new listitem("select lcid..", 0); dropdownlist1.items.insert(0, selectoneplease); }

vb:

protected sub insertchooseitem(sender object, e eventargs) dim selectoneplease new listitem("select lcid..", 0) dropdownlist1.items.insert(0, selectoneplease) end sub

asp.net sql database drop-down-menu

No comments:

Post a Comment