【发布时间】:2013-04-17 10:39:57
【问题描述】:
我发布了一个类似的 RBL 问题,但我遇到了一个新问题,所以我想我会发布一个新帖子。
这是我的代码:
页面加载
protected void Page_Load(object sender, EventArgs e)
{
//Output Success/Error Message
if (Session["formProcessed"] != null)
{
Label lblMessage = (Label)Master.FindControl("lblMessage");
new Global().DisplayUserMessage("success", Session["formProcessed"].ToString(), lblMessage);
}
Session.Remove("formProcessed");
if (Page.IsPostBack == false)
{
rblContentTypesGetAll.DataBind();
}
}
rblContentTypesGetAll_Load
protected void rblContentTypesGetAll_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataTable dt = new DataTable();
using (SqlConnection con = new SqlConnection(Global.conString))
using (SqlCommand cmd = new SqlCommand("contentTypeGetAll", con))
using (SqlDataAdapter da = new SqlDataAdapter(cmd))
{
da.Fill(dt);
}
//Clear Items before reloading
rblContentTypesGetAll.Items.Clear();
//Populate Radio button list
for (int i = 0; i < dt.Rows.Count; i++)
{
rblContentTypesGetAll.Items.Add(new ListItem(dt.Rows[i]["contentType"].ToString() + " - " + dt.Rows[i]["description"].ToString(),
dt.Rows[i]["ID"].ToString()));
}
//Set Default Selected Item by Value
rblContentTypesGetAll.SelectedIndex = rblContentTypesGetAll.Items.IndexOf(rblContentTypesGetAll.Items.FindByValue(((siteParams)Session["myParams"]).DefaultContentType.ToLower()));
}
}
HTML/ASP.NET 前端
<asp:RadioButtonList id="rblContentTypesGetAll" OnLoad="rblContentTypesGetAll_Load" runat="server">
</asp:RadioButtonList>
我一提交表单,selectedValue 似乎就变成了空白。我在做什么明显不正确?
【问题讨论】:
标签: c# server-side radiobuttonlist