can't get data from database to dropdownlist in loginview

Posted by Thomas Bøg Petersen on Stack Overflow See other posts from Stack Overflow or by Thomas Bøg Petersen
Published on 2012-09-13T14:30:50Z Indexed on 2012/09/13 21:38 UTC
Read the original article Hit count: 504

Filed under:
|
|
|

I have this code on an aspx page.

<asp:DropDownList runat="server" ID="ddlSize" CssClass="textbox" Width="100px">
<asp:ListItem Value="" Text="" />
<asp:ListItem Value="11" Text="11. Mands" />
<asp:ListItem Value="7" Text="7. Mands" />
<asp:ListItem Value="" Text="Ikke Kamp"/>
</asp:DropDownList>


 <asp:DropDownList runat="server" ID="ddlType" CssClass="textbox" Width="100px">
 <asp:ListItem Value="" Text="" />
 <asp:ListItem Value="K" Text="Kamp" />
 <asp:ListItem Value="T" Text="Træning" />
 <asp:ListItem Value="E" Text="Aktivitet"/>
 </asp:DropDownList>

ts inside a loginview with some other fields (textbox) Im trying to get a record id into the page so i can edit it, I have fix it with the Textbox and its working 100%, but i cant get the value from the database into the dropdownlist so it show that value as selected. I have tryed these 3 codes, but nothing is working fore the dropdownlist.

// DataValueField               
Dim drop_obj As DropDownList = TryCast(LoginView2.FindControl("ddlSize"), DropDownList)
drop_obj.DataValueField = dtEvents.Rows(0)("EventEventSize")

Dim drop_obj2 As DropDownList = TryCast(LoginView2.FindControl("ddlType"), DropDownList)
drop_obj2.DataValueField = dtEvents.Rows(0)("EventType")

// SelectedIndex
Dim drop_obj As DropDownList = TryCast(LoginView2.FindControl("ddlSize"), DropDownList)
drop_obj.SelectedIndex = dtEvents.Rows(0)("EventEventSize")

Dim drop_obj2 As DropDownList = TryCast(LoginView2.FindControl("ddlType"), DropDownList)
drop_obj2.SelectedIndex = dtEvents.Rows(0)("EventType")

// SelectedValue
Dim drop_obj As DropDownList = TryCast(LoginView2.FindControl("ddlSize"), DropDownList)
drop_obj.SelectedValue = dtEvents.Rows(0)("EventEventSize")

Dim drop_obj2 As DropDownList = TryCast(LoginView2.FindControl("ddlType"), DropDownList)
drop_obj2.SelectedValue = dtEvents.Rows(0)("EventType")

Can someone plz. help !? I have values in the 2 dtEvents.Rows(0) i have checked that, with a debug and then step-into. and i get values like 7 or 11 and T or K.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about vb.net