gpt4 book ai didi

c# - 工资列未在 Gridview 中更新

转载 作者:太空宇宙 更新时间:2023-11-03 13:18:40 25 4
gpt4 key购买 nike

我希望用户在点击“编辑”时能够编辑薪水列。场景就像,如果用户没有在工资文本框中输入任何值,它应该显示“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>

请帮助,如何实现这一目标。

最佳答案

简单检查:

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

如果您的代码重复,您应该重构代码以将 if-else 代码移动到单独的函数中。

关于c# - 工资列未在 Gridview 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25131929/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com