0
Answer

Setting CB cntrl in FormV in FV1_DataBinding()

Ask a question
Shawn Austin

Shawn Austin

11y
703
1
So I thought I would list this question under a different subject. I am trying to set 5 different checkbox formview fields at runtime. I need help with the syntax.
I am trying to set a formview checkbox.checked on the server page using an if stmt to see what option was selected in a record from the sql db.
I am not getting the syntax right and I need some help. Below is the client code and the tenative server sided code. I am using VS 2012, c#, and asp.net 4.0/4.5.
This is the field in the formview that is set to the record field with the value.

<asp:Label ID="lbloptionselc" runat="server" Visible="False" Text='<%# Eval("RepaymentOptId") %>'></asp:Label>

This is the server side page code for determining the checkbox to set to "Checked":


protected void FormView1_DataBinding(object sender, EventArgs e)
{
Label lbloption = new Label();
lbloption.Text =
this.FormView1.FindControl("lbloptionselc").ToString();
string formoption = lbloption.Text.ToString();
if (formoption == "1")
{
CheckBox cboption = new CheckBox ();
cboption.Checked =
true;
this.FormView1.FindControl("chkopt1")????????????? = true;  *****************   WHAT IS THE CORRECT SYNTAX HERE ???


}
else
if (formoption == "2")
{
}
else
if (formoption == "3")
{
}
else
if (formoption == "4")
{
}
else
if (formoption == "5")
{
}
else
{
}

}