我試圖從數據庫檢索數據並將它們設置爲在Dropdownlist中的SelectedValue和單選按鈕列表。無法顯示數據庫數據爲SelectedValue asp.net c#
問題是,數據正在被檢索,並且可以在標籤中設置爲文本時顯示,但無法顯示在下拉列表和單選按鈕列表中。編碼看起來很好,但沒有顯示。所以我需要幫助,看看什麼時候錯了?
texttime和txttime1可以顯示結果,但只有ddlEditEventStatus,ddlAddMembershiplist2和RadioButtonList1。
代碼隱藏:
this.dvUpdate.Visible = true;
//force databinding
DataSet ds = dal.getEditEventDetails(promoID);
this.dvUpdate.DataSource = ds;
this.dvUpdate.DataBind();
this.mdlPopup2.Show();
populatePanelDDL4UpdateEvent(ds.Tables[0].Rows[0]["membershipType"].ToString());
//remember the session of the old name
Session["oldTitle"] = ds.Tables[0].Rows[0]["titlePromo"].ToString();
((RadioButtonList)dvUpdate.FindControl("RadioButtonList1")).SelectedValue = ds.Tables[0].Rows[0]["defaults"].ToString();
//set eventCancelledStatus
//set the time
//((Label)dvUpdate.FindControl("Label3")).Text = ds.Tables[0].Rows[0]["defaults"].ToString();;
((DropDownList)dvUpdate.FindControl("ddlEditEventStatus")).SelectedValue = ds.Tables[0].Rows[0]["promoStatus"].ToString();
((DropDownList)dvUpdate.FindControl("ddlAddMembershiplist2")).SelectedValue = ds.Tables[0].Rows[0]["membershipType"].ToString();
((DropDownList)dvUpdate.FindControl("txttime")).Text = ds.Tables[0].Rows[0]["startTime"].ToString();
((DropDownList)dvUpdate.FindControl("txttime1")).Text = ds.Tables[0].Rows[0]["endTime"].ToString();
HTML:
<td class="fields">
<asp:DropDownList ID="ddlEditEventStatus" CssClass="selectMidStyle" Width="255px" runat="server">
<asp:ListItem Text="Opened" Value="Opened"></asp:ListItem>
<asp:ListItem Text="Closed" Value="Closed"></asp:ListItem>
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="text">
<asp:Label ID="add_membershipList2" runat="server" Text=" Membership Type : "></asp:Label>
</td>
<td colspan="3">
<asp:DropDownList ID="ddlAddMembershiplist2" runat="server" Width="255px" CssClass="selectMidStyle">
</asp:DropDownList>
</td>
</tr>
<tr>
<td class="text">
</br>
<asp:Label ID="Label3" runat="server" Text=" Default Promotion : "></asp:Label>
</td>
<td>
</br>
<asp:RadioButtonList ID="RadioButtonList1" runat="server" ValidationGroup="EditValidationGp">
<asp:ListItem Value="Y">Yes</asp:ListItem>
<asp:ListItem Value="N">No</asp:ListItem>
</asp:RadioButtonList>
</td>
在顯示所選值之前,您必須綁定DropDownList或RadioButtonList。我沒有找到你的下拉列表綁定方法。所以首先綁定DropDownList與適當的值,然後設置SelectedValue。 –
我的dropdownlist listitem是從數據庫值創建的 – lel