文本框不会改变onLoad

时间:2014-10-02 09:07:32

标签: c# asp.net postback

我有一个Formview和一些绑定的控件。在我的数据库中,我有另一个表,其位值与Formview中的控件相匹配。在我加载aspx页面时,我想将一些文本框从启用更改为禁用,如果我在数据库中有一个tic,但这个naver发生了。我认为是因为onLoad页面已经创建但我不知道如何解决这个问题。这是我的代码:

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;
    }

    }
}

这是我的aspx代码:

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

0 个答案:

没有答案