Gridview中没有更新工资栏

本文关键字:更新 Gridview | 更新日期: 2023-09-27 18:16:19

我希望用户在点击编辑时应该能够编辑工资栏。场景是这样的,如果用户没有在工资文本框中输入任何值,它应该显示"00000",也应该进入表格。如果用户在edit上输入了任何值,比如他输入了65000,它也应该被更新。

这里,只有静态数据像00000一样。但是在运行时,这个列没有得到更新。

注意:点击查看,页面重定向到用户放置数据的另一个页面。

 protected void btnAdd_Click(object sender, EventArgs e)
{
    if (Page.IsValid)
    {
        string salary = "00000";
        if (hdnjobId.Value == "0")
        {
            Job newjob = new Job();
            newjob.JobCode = GenerateJobCode();
            newjob.EmpName = txtPostedByName.Text.Trim();
            newjob.EmpCode = txtPostedByEmpCode.Text.Trim();
            newjob.EmailId1 = txtEmailId1.Text;
            newjob.EmailId2 = txtEmailId2.Text;
            newjob.Position = txtPosition.Text;
            newjob.Location = ddlLocation.SelectedValue;
            newjob.BusinessUnit = ddlBusinessUnit.SelectedValue;
            newjob.EduReq = txtEduReq.Text;
            newjob.MinExp = txtMinExp.Text;
            newjob.MinExpYrs = ddlMinExpYr.SelectedValue;
            newjob.MaxExp = txtMaxExp.Text;
            newjob.MaxExpYrs = ddlMaxExpYr.SelectedValue;
            if (txtSalaryRange2.Enabled == true)
            {
                newjob.SalaryRange = salary;
                txtSalaryRange.Enabled = false;
            }
            newjob.SalaryRange = txtSalaryRange.Text;
            newjob.Description = txtJobDesc.Text;
            newjob.Skills = txtSkills.Text;
            newjob.DateOfPosting = Convert.ToDateTime(txtJobPostingDate.Text);
            newjob.DateOfClosing = Convert.ToDateTime(txtJobClosingDate.Text);
            newjob.Status = chkStatus.Checked;
            _helper.Save(newjob);
            ClientScript.RegisterStartupScript(this.GetType(), "added", "alert('Job added successfully'); location.href = 'CareerJobList.aspx';", true);
        }
        else
        {
            var newjob = _helper.GetJob(Convert.ToInt32(hdnjobId.Value));
            newjob.JobCode = lblJobCode.Text;
            newjob.EmpName = txtPostedByName.Text.Trim();
            newjob.EmpCode = txtPostedByEmpCode.Text.Trim();
            newjob.EmailId1 = txtEmailId1.Text;
            newjob.EmailId2 = txtEmailId2.Text;
            newjob.Position = txtPosition.Text;
            newjob.Location = ddlLocation.SelectedValue;
            newjob.BusinessUnit = ddlBusinessUnit.SelectedValue;
            newjob.EduReq = txtEduReq.Text;
            newjob.MinExp = txtMinExp.Text;
            newjob.MinExpYrs = ddlMinExpYr.SelectedValue;
            newjob.MaxExp = txtMaxExp.Text;
            newjob.MaxExpYrs = ddlMaxExpYr.SelectedValue;
            if (txtSalaryRange2.Enabled == true)
            {
               // newjob.SalaryRange = salary;
                txtSalaryRange.Enabled = false;
            }
            else
            {
                txtSalaryRange2.Enabled = false;
                newjob.SalaryRange = txtSalaryRange.Text;
            }
            //newjob.SalaryRange = txtSalaryRange.Text;
            newjob.Description = txtJobDesc.Text;
            newjob.Skills = txtSkills.Text;
            newjob.DateOfPosting = Convert.ToDateTime(txtJobPostingDate.Text);
            newjob.DateOfClosing = Convert.ToDateTime(txtJobClosingDate.Text);
            newjob.Status = chkStatus.Checked;
            _helper.Save(newjob);
            ClientScript.RegisterStartupScript(this.GetType(), "added", "alert('Job updated successfully');location.href='CareerJobList.aspx';", true);
        }
    }
}

参见aspx代码:-

<tr>
                <td class="td">Salary</td>
                <td>
                    <asp:TextBox CssClass="txtfld-popup" ID="txtSalaryRange" runat="server" MaxLength="5"></asp:TextBox><span style="color: #CF060D;">lakhs per annum</span>
                    <asp:TextBox CssClass="txtfld-popup" ID="txtSalaryRange2" runat="server" Visible="false"></asp:TextBox><span style="color: #CF060D;"></span>
                    <asp:RequiredFieldValidator CssClass="error_msg" ID="reqSalaryRange" runat="server" ControlToValidate="txtSalaryRange" ErrorMessage="Please enter salary" SetFocusOnError="true"> </asp:RequiredFieldValidator>
                  <%--  <span style="color: #f00;">lakhs per annum</span>--%>
                     <asp:RegularExpressionValidator  CssClass="error_msg" ID="RegularExpressionValidator1"  ControlToValidate="txtSalaryRange" runat="server" ErrorMessage="Invalid Salary" ValidationExpression="^[1-9][0-9]*('.[0-9]+)?|0+'.[0-9]*[1-9][0-9]*$"></asp:RegularExpressionValidator>
                    <asp:RadioButton ID="rbButtonYes" runat="server" Text="Show" GroupName="salary" AutoPostBack="true"  OnCheckedChanged="rbButtonYes_CheckedChanged"/> &nbsp;&nbsp;
                    <asp:RadioButton ID="rbButtonNo" runat="server" Text="Not Show" GroupName="salary" OnCheckedChanged="rbButtonNo_CheckedChanged" AutoPostBack="true" />
                </td>
            </tr>

请帮助,如何实现这一点

Gridview中没有更新工资栏

简单检查:

if (!string.IsNullOrEmpty(txtSalaryRange.Text))
{
   newjob.SalaryRange = txtSalaryRange.Text;
}
else
{
   newjob.SalaryRange = "00000";
}

如果你的代码是重复的,你应该重构你的代码,把if-else代码移到一个单独的函数中。