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.
I think you’re trying to datebind your table to your list.
You want to utilize these two properties:
So, you want to set your
DataTextField(what the user will see) to the column taht contains the display text and then you want to set yourDataValueField(the value of the item that won’t be seen) to the column containing that. Then you want to callDataBind().For example (my VB is very rusty):
Definitely check that syntax. I’ve been using C# for months and no VB, so that’s probably not 100%.