工资列未在Gridview中更新

时间:2014-08-05 05:47:51

标签: c# asp.net

我希望用户在点击编辑时应该能够编辑薪水cloumn。场景就像是,如果用户没有在工资文本框中输入任何值,它应显示" 00000"也应该进入表格。如果用户对其进行任何编辑,就像他输入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>

请帮助,如何实现这一点。

1 个答案:

答案 0 :(得分:1)

只需检查:

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

您的代码是重复的,您应该重新考虑代码以将if-else代码移动到单独的函数中。