更新面板中的数据未保存在数据库中

Data in update panel is not save in database

我想将模式中的数据保存在数据库的更新面板中。

我的文本框中的值在保存在那里的变量后面,但没有保存在数据库中。我不知道为什么。我每次都使用 updModal.Update();,因为模态是通过列表视图从数据库中获取的。

这是我的模态代码:

<div class="modal fade" id="studinfo" role="dialog">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h4 class="modal-title">Student Info</h4>
                <button type="button" class="close"
                    data-dismiss="modal">
                    &times;</button>
            </div>
            <div class="modal-body">
                    <asp:UpdatePanel ID="updModal" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">
                <contenttemplate>
                    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

                    <div class="card h-100">
                        <div class="card-body">
                            <ul class="list-group list-group-flush">
                                <asp:TextBox ID="txtId" Visible="false" runat="server"></asp:TextBox>
                                <asp:Panel ID="typepannel" CssClass="list-group-item" runat="server">
                                    <asp:Label ID="lbltype" runat="server"
                                        Font-Bold="true" Text="Candidate Type: "></asp:Label>
                                    <asp:Label ID="type" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </asp:Panel>

                                <asp:Panel ID="colpanel" CssClass="list-group-item" runat="server">
                                    <asp:Label ID="lblCol" runat="server"
                                        Font-Bold="true" Text="College Attend: "></asp:Label>
                                    <asp:Label ID="college" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </asp:Panel>

                                <div class="list-group-item">
                                    <asp:Label ID="lblName" runat="server"
                                        Font-Bold="true" Text="Name: "></asp:Label>
                                    <asp:Label ID="Name" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblNic" runat="server"
                                        Font-Bold="true" Text="Nic: "></asp:Label>
                                    <asp:Label ID="Nic" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblAge" runat="server"
                                        Font-Bold="true" Text="Age: "></asp:Label>
                                    <asp:Label ID="Age" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblAdress" runat="server"
                                        Font-Bold="true" Text="Address: "></asp:Label>
                                    <asp:Label ID="Address" runat="server"
                                        Text=''>
                                    </asp:Label>

                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblacad" runat="server"
                                        Font-Bold="true" Text="Academy: "></asp:Label>
                                    <asp:Label ID="Academy" runat="server"
                                        Text=''>
                                    </asp:Label>
                                </div>

                                <h6 class="mt-3 mb-3">Parent in Charge</h6>
                                <div class="list-group-item">
                                    <asp:Label ID="lblParent" runat="server"
                                        Font-Bold="true" Text="Parent Name: "></asp:Label>
                                    <asp:Label ID="parentName" runat="server"
                                        Text=''>
                                    </asp:Label>
                                </div>
                                <div class="list-group-item">
                                    <asp:Label ID="lblNumber" runat="server"
                                        Font-Bold="true" Text="Parent Contact Number: "></asp:Label>
                                    <asp:Label ID="Number" runat="server"
                                        Text=''>
                                    </asp:Label>
                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblEmail" runat="server"
                                        Font-Bold="true" Text="Parent Email Address: "></asp:Label>
                                    <asp:Label ID="Email" runat="server"
                                        Text=''>
                                    </asp:Label>
                                </div>

                                <div class="list-group-item">
                                    <asp:Label ID="lblResult" runat="server"
                                        Font-Bold="true" Text="Result: "></asp:Label>
                                    <asp:DropDownList ID="ddlResult"
                                        CssClass="select form-control"
                                        runat="server">
                                    </asp:DropDownList>

                                </div>


                                <div class="list-group-item">
                                    <asp:Label ID="lblMarks" runat="server" Font-Bold="true" Text="Marks: "></asp:Label>
                                    <asp:TextBox runat="server" ID="txtMarks"
                                        CssClass="form-control form-control-lg" />
                                    <asp:RequiredFieldValidator ID="rfvMarks" runat="server"
                                        Display="Dynamic" ForeColor="Red"
                                        ControlToValidate="txtMarks"
                                        SetFocusOnError="true"
                                        ErrorMessage="Marks is Mandatory">
                                    </asp:RequiredFieldValidator>
                                    <asp:CompareValidator ID="cmpVMarks" runat="server"
                                        ControlToValidate="txtMarks"
                                        Operator="DataTypeCheck"
                                        Type="Double"
                                        SetFocusOnError="true"
                                        Display="Dynamic"
                                        Text="Incorect data type"
                                        ForeColor="Red"
                                        ErrorMessage="Invalid">
                                    </asp:CompareValidator>
                                    <asp:RegularExpressionValidator ID="revPhone"
                                        runat="server"
                                        ControlToValidate="txtMarks"
                                        SetFocusOnError="true"
                                        Display="Dynamic"
                                        ForeColor="Red"
                                        ValidationExpression="^\d\d+(\.[1-9])?$"
                                        ErrorMessage="Invalid">

                                    </asp:RegularExpressionValidator>
                                </div>
                                <div class="list-group-item">
                                    <asp:Label ID="lblpurcentage" runat="server"
                                        Font-Bold="true" Text="Purcentage : "></asp:Label>
                                    <asp:TextBox runat="server" ID="txtpur"
                                        CssClass="form-control form-control-lg" />
                                    <asp:RequiredFieldValidator
                                        ID="rfvpur" runat="server"
                                        Display="Dynamic" ForeColor="Red"
                                        ControlToValidate="txtpur"
                                        SetFocusOnError="true"
                                        ErrorMessage="Purcentage is Mandatory">
                                    </asp:RequiredFieldValidator>
                                    <asp:CompareValidator ID="cvpur" runat="server"
                                        ControlToValidate="txtpur"
                                        Operator="DataTypeCheck"
                                        Type="Double"
                                        SetFocusOnError="true"
                                        Display="Dynamic"
                                        Text="Incorect data type"
                                        ForeColor="Red"
                                        ErrorMessage="Invalid">
                                    </asp:CompareValidator>
                                </div>
                            </ul>
                        </div>

                    </div>

                 
                                            </ContentTemplate>

                </asp:UpdatePanel>

                   <asp:Button ID="btnSave" OnClick="btnSave_Click" CausesValidation="false"
                        CssClass="btn btn-success btn-block" runat="server" Text="Save" />
            </div>
        </div>

保存按钮的隐藏代码如下:

    protected void btnSave_Click(object sender, EventArgs e)
    {

        try
        {
            updModal.Update();

           
            string id = txtId.Text;
            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "update tblStudent set stud_result=@res,stud_purcentage=@pur,stud_totalMarks=@marks where stud_Id=@id";
            cmd.Parameters.AddWithValue("@id", id);
            cmd.Parameters.AddWithValue("@res", ddlResult.SelectedValue);
            cmd.Parameters.AddWithValue("@pur", txtpur.Text.Trim());
            cmd.Parameters.AddWithValue("@marks", txtMarks.Text.Trim());
            con.Open();
            cmd.Connection = con;

            Label1.Text = txtId.Text;
            gridView();
          
        }
        catch (Exception ex)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "LaunchServerSide",
                      "$(function () { showUErrorModal(); });", true);

        }
        finally
        {

            con.Close();

        }

    }

在Label1.Text之前=txtId.Text;你写 cmd.ExecuteNonQuery()