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!

dropdownlist not showing value stored

Status
Not open for further replies.

zma

Programmer
May 30, 2006
25
US
THIS IS HOW DROPDOWNLIST1 IS SET UP. THERE ARE 2 LISTITEMS
THAT ARE PUT IN THAT ARE NOT FROM SQLDATASOURCE1, "" AT THE TOP AND "aa" JUST BELOW THAT.

<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="ds1" DataTextField="code"
DataValueField="code" AppendDataBoundItems=true>
<asp:listitem value=""></asp:listitem>
<asp:listitem value="aa"></asp:listitem>
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ %>"
SelectCommand="SELECT *
FROM [Codes]
WHERE ([fldname]=@fldname)">
<SelectParameters>
<asp:parameter
DefaultValue="CUSTOMER" Name="Fldname" Type="String" />
</SelectParameters>
</asp:SqlDataSource>

<asp:Label ID="Label2" runat="server" Text="Label" </asp:Label>

HERE IS PART OF THE CODE BEHIND. WHEN I TRY TO DISPLAY THE ITEM WITH THE VALUE READER1("CUSTOMER") WHICH IS DOWN IN THE LIST, DROPDOWNLIST1 JUST STAYS AT THE TOP,AT "". READER1("CUSTOMER") APPEARS CORRECT IN LABEL2.
HOW DO I GET IT TO WORK FOR READER1("CUSTOMER")?

If reader1.Read() Then
Label2.Text = "*" & reader1("customer") & "*"
TextBox1.Text = reader1("cno")
TextBox2.Text = reader1("service")

'DropDownList1.SelectedIndex = _
' DropDownList1.Items.IndexOf(DropDownList1.Items.FindByValue(reader1("customer")))
Else
Response.Write("nothing")
End If

 
Have you tried

Code:
DropDownList1.SelectedValue =  reader1("customer")

if reader("customer") isn't a string, convert it to one. sorry, don't do VB :)
 
In VB doesn't an apostrophe (') denote a comment? And your lines that try to set the SelectedIndex both begin with apostrophes...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top