0
我在aspx頁面上有此代碼。一個loginview內無法從數據庫中獲取數據到登錄視圖中的下拉列表
<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與其他一些領域(文本) 我試着去得到一個記錄id到頁面,所以我可以編輯它,我有一個文本框和其工作100%修復它,但我無法從數據庫中獲取值到下拉列表中,因此它顯示該值爲選中狀態。 我已經嘗試了這3個代碼,但沒有任何工作在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")
有人可以。幫幫我 !?我有2個dtEvents.Rows(0)中的值,我檢查了一下,然後進行調試。 和我得到像7或11和T或K的值。