0

I have a Formview and some controls that are bound. In my database I have another table with bit values matching the controls from Formview. On I load the aspx page, I want to change some textboxs from enable to disable if I have a tic in Database, but this naver happened.I think is bacause onLoad page is already created but I don`t know how to solve this.Here is my code:

protected void Page_Load(object sender, EventArgs e)
        {
    if(!Page.IsPostBack)
                {
                    if (HttpContext.Current.Request.Url.AbsoluteUri.Contains("Id"))
                    {
                        ASPxComboBox ComboCentruFormare = (ASPxComboBox)FormViewDateInscriere.FindControl("ComboCentruFormare");
                        TextBox tbNume = (TextBox)FormViewDateInscriere.FindControl("tbnume");
                        TextBox tbPrenume = (TextBox)FormViewDateInscriere.FindControl("tbPrenume");
    //.......and some other textboxs
    FormViewDateInscriere.ChangeMode(FormViewMode.Edit);
                        ObjectDataSource1.SelectParameters["Id"].DefaultValue = Request.QueryString["Id"].ToString();
                        ObjectDataSource1.DataBind();
                        SqlConnection conn = new SqlConnection("Data Source=.\\sqlexpress;Initial Catalog=Elearning;Integrated Security=True");
                        conn.Open();

                        SqlCommand cmd = new SqlCommand("Select * from ELR_CursantiBife where id='" + Request.QueryString["Id"].ToString() + "'", conn);//this is the table with bit values
                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
    {
    if ((bool)reader["Nume"] == false)
            tbNume.Enabled = false;
    if ((bool)reader["Prenume"] == false)
            tbPrenume.Enabled = false;
    }

    }
}

Here is my aspx code:

<asp:FormView ID="FormViewDateInscriere" runat="server" DefaultMode="Insert" 
 style="margin-right: 82px" DataKeyNames="Id" 
            DataSourceID="ObjectDataSource1">
            <EditItemTemplate>
            <fieldset>
            <table>
            <tr>
            <td>
                Alegeți centrul de formare
                    <dx:ASPxComboBox ID="ComboCentruFormare" runat="server" 
                    Value='<%# Bind("Centrul_de_formare") %>' >
                    </dx:ASPxComboBox>
               </td>
               </tr>
               </table>
            </fieldset>


                  <fieldset>
           <legend>Date personale</legend>

            <table class="style1">
                <tr>
                    <td>
                        Nume:</td>
                    <td class="style2">
                        <asp:TextBox ID="tbnume" runat="server" Height="23px" 
                            Text='<%# Bind("Nume") %>' style="text-align: left" 
                            ></asp:TextBox>
                    </td>
                    <td class="style9">
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;</td>
                    <td>
                        Prenume:</td>
                    <td class="style2">
                        <asp:TextBox ID="tbPrenume" runat="server" Text='<%# Bind("Prenume") %>' 
                            ></asp:TextBox>
GreenAsJade
  • 14,459
  • 11
  • 63
  • 98
user3542654
  • 293
  • 2
  • 7

0 Answers0