ASP.NET Radio-Button-Liste | SelectedValue kommen NULL

Ich habe eine ähnliche RBL Frage habe ich aber ein neues Problem entstehen, so dass ich dachte, ich würde einen neuen Eintrag machen.

Hier ist mein code:

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-front-end -

 <asp:RadioButtonList id="rblContentTypesGetAll" OnLoad="rblContentTypesGetAll_Load"  runat="server">
        </asp:RadioButtonList>

Sobald ich das Formular abschicken es scheint, die selectedValue leer wird. Was mache ich, das ist so offensichtlich falsch?

InformationsquelleAutor balexander | 2011-02-23
Schreibe einen Kommentar