我發佈了一個類似的RBL問題,但我遇到了一個新問題,所以我想我會發一個新帖子。ASP.NET單選按鈕列表| SelectedValue來了NULL
這裏是我的代碼:
的Page_Load
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>
當我提交表單一世t似乎selectedValue
變成空白。我在做什麼這顯然是不正確的?
我想殺死'view-state' – Arshad 2014-07-05 11:46:03