我有一个页面,如果我在不添加附件的情况下提交表单, 我收到消息为 "请附上..,..,..,"
的文件但现在我想以如下序列显示: -
请附上
文件SR.No AttachmentName Attached(Y / N)
以下是我的代码: -
protected void btnSave_Click(object sender, EventArgs e)
{
DataTable dtAttach = new DataTable();
List<string> attachMan = new List<string>();
string strerrmsg = string.Empty;
attachMan.Add("Birth Certificate~BC");
attachMan.Add("PAN Certificate~PNC");
attachMan.Add("UAN Certificate~UAN");
attachMan.Add("Gratuity Certificate~GRAT");
attachMan.Add("Nomination Certificate~NOC");
attachMan.Add("Permanent Address~RAC");
if (txtHouseNumber_Per.Text + txtStreetNumber_Per.Text + txtArea_Per.Text + txtLandMark_Per.Text + txtCity_Per.Text + txtPinCode_Per.Text +
txtState_Per.Text + txtTelephoneNum_Per.Text + txtMobileNum_Per.Text !=
txtHouseNum_M.Text + txtStreetNum_M.Text + txtArea_M.Text + txtLandmark_M.Text + txtCity_M.Text + txtPinCode_M.Text +
txtState_M.Text + txtTelephoneNum_M.Text + txtMobileNumber_M.Text)
{
attachMan.Add("Mailing Address Proof~PAC");
}
if (TxtPassportNo.Text != "") attachMan.Add("Passport~PC");
for (int i = 0; i < attachMan.Count; i++)
{
string[] arrMsg = attachMan[i].Split(new char[] { '~' });
string strmsg = CF.ExecuteScaler("select count(*) from EMP_ATTACHED_DOCUMENTS " +
"where pk1_value = '" + txtEmpCode.Text + "' and " +
"category_id in ('" + arrMsg[1] + "')");
if (strmsg == "0") strerrmsg += arrMsg[0] + ", ";
}
if (strerrmsg != "")
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "CloseScript", "alert('Please Attach file for " + strerrmsg.ToString() + " ');", true);
}
else
{
funsave();
}
}
请建议做什么
答案 0 :(得分:0)
使用ASP.NET Validation Controls:
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>Birth Certificate:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox1" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator1"
ControlToValidate="TextBox1"
ErrorMessage="Birth Certificate."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>>
</tr>
<tr>
<td>PAN Certificate:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox2" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator2"
ControlToValidate="TextBox2"
ErrorMessage="PAN Certificate."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>>
</tr>
<tr>
<td>UAN Certificate:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox3" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator3"
ControlToValidate="TextBox3"
ErrorMessage="UAN Certificate."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>>
</tr>
<tr>
<td>Gratuity Certificate:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox4" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator4"
ControlToValidate="TextBox4"
ErrorMessage="Gratuity Certificate."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>>
</tr>
<tr>
<td>Nomination Certificate:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox5" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator5"
ControlToValidate="TextBox5"
ErrorMessage="Nomination Certificate."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>>
</tr>
<tr>
<td>Permanent Address:</td>
<td>
<asp:TextBox runat="server" Width="200px" ID="TextBox6" />
<asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator6"
ControlToValidate="TextBox6"
ErrorMessage="Permanent Address."
Display="dynamic">*</asp:RequiredFieldValidator>
</td>
</tr>
</table>
<br />
<asp:Button runat="server" Text="Submit" ID="Submit" OnClick="Submit_Click" /><br />
<br />
<asp:ValidationSummary runat="server" ID="Summary"
DisplayMode="BulletList"
HeaderText="Please attach files for the following documents:"
ShowMessageBox="true"
ShowSummary="False" />
</div>
</form>
答案 1 :(得分:0)
我试着在这上面得到一个答案。事情需要改变一点,但我终于设法处理它。
我走了: -
protected void btnSave_Click(object sender, EventArgs e)
{
DataTable dtAttach = new DataTable(); string strpmsg = "";
List<string> attachMan = new List<string>();
string strerrmsg = string.Empty;
attachMan.Add("Birth Certificate~BC");
attachMan.Add("PAN Certificate~PNC");
attachMan.Add("UAN Certificate~UAN");
attachMan.Add("Gratuity Certificate~GRAT");
attachMan.Add("Nomination Certificate~NOC");
attachMan.Add("Permanent Address~RAC");
if (txtHouseNumber_Per.Text + txtStreetNumber_Per.Text + txtArea_Per.Text + txtLandMark_Per.Text +
txtCity_Per.Text + txtPinCode_Per.Text + txtState_Per.Text + txtTelephoneNum_Per.Text + txtMobileNum_Per.Text !=
txtHouseNum_M.Text + txtStreetNum_M.Text + txtArea_M.Text + txtLandmark_M.Text +
txtCity_M.Text + txtPinCode_M.Text + txtState_M.Text + txtTelephoneNum_M.Text + txtMobileNumber_M.Text)
{
attachMan.Add("Mailing Address Proof~PAC");
}
if (TxtPassportNo.Text != "") attachMan.Add("Passport~PC");
for (int i = 0; i < attachMan.Count; i++)
{
string[] arrMsg = attachMan[i].Split(new char[] { '~' });
string strmsg = CF.ExecuteScaler("select count(*) from EMP_ATTACHED_DOCUMENTS " +
"where pk1_value = '" + txtEmpCode.Text + "' and " +
"category_id in ('" + arrMsg[1] + "')");
if (strmsg == "0")
{
strerrmsg += (i + 1).ToString() + ". " + arrMsg[0] + " (pending)\\n"; **// Pending message**
strpmsg = "pending";
}
else
{
strerrmsg += (i + 1).ToString() + ". " + arrMsg[0] + " (attached)\\n"; **// Attached message**
}
}
// string condition1 = ""; string condition2 = "";
/* if (txtHouseNumber_Per.Text + txtStreetNumber_Per.Text + txtArea_Per.Text + txtLandMark_Per.Text + txtCity_Per.Text + txtPinCode_Per.Text +
txtState_Per.Text + txtTelephoneNum_Per.Text + txtMobileNum_Per.Text ==
txtHouseNum_M.Text + txtStreetNum_M.Text + txtArea_M.Text + txtLandmark_M.Text + txtCity_M.Text + txtPinCode_M.Text +
txtState_M.Text + txtTelephoneNum_M.Text + txtMobileNumber_M.Text)
{
condition1 = "'PC', 'PAC', 'TC', 'PEC', 'ADC', 'EPF', 'ESIC', 'EPS', 'GRAT', 'NOC'";
condition2 = "'PEC', 'TC','PAC', 'PC', 'ADC', 'EPF', 'ESIC','EPS', 'GRAT', 'NOC'";
}
else
{
condition1 = "'PC','TC', 'PEC', 'ADC', 'EPF', 'ESIC','EPS', 'GRAT', 'NOC'";
condition2 = "'PEC', 'TC', 'PC', 'ADC', 'EPF', 'ESIC','EPS', 'GRAT', 'NOC'";
}
if (chkPrevData.Checked == true)
{
dtAttach = CF.ExecuteDT("SELECT stuff((Select ',' + Type_desc from type_mst_a where Type_code = 'AC' " +
"and NOT Type_Abbr in(" + condition1 + ") and type_abbr NOT IN (select category_id from EMP_ATTACHED_DOCUMENTS " +
"where pk1_value = '" + txtEmpCode.Text + "')for xml path('')),1,1,'') Categories");
}
else
{
dtAttach = CF.ExecuteDT("SELECT stuff((Select ',' + Type_desc from type_mst_a where Type_code = 'AC' " +
"and NOT Type_Abbr in(" + condition2 + ") and type_abbr NOT IN (select category_id from EMP_ATTACHED_DOCUMENTS " +
"where pk1_value = '" + txtEmpCode.Text + "')for xml path('')),1,1,'') Categories");
} */
// Int32 intcnt = Convert.ToInt32(CF.ExecuteScaler("select count(*) cnt from EMP_ATTACHED_DOCUMENTS " +
// "where pk1_value = '" + txtEmpCode.Text + "' and category_id='PP'"));
// if (dtAttach.Rows.Count > 0 && dtAttach.Rows[0][0].ToString() != "")
if (strpmsg != "")
{
Page.ClientScript.RegisterStartupScript(typeof(Page), "CloseScript", "alert('Status of Attached file\\s are as \\n" + strerrmsg.ToString() + " ');", true);
}
else
{
funsave();
}
}
谢谢你所有的建议朋友。