在使用JavaScript在RadGrid中选中复选框时,如何验证文本框? 我试图使用CheckBox_CheckedChanged事件,但它无法正常工作。请告诉我如何在ASP.NET中的RadGrid中选中复选框时验证文本框是否为空。
C#:
protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
{
foreach (GridDataItem item in radGridSahreaJob.MasterTableView.Items)
{
TextBox txtMaxResumes = (TextBox)item.FindControl("txtMaxResumes");
CheckBox chkBox = (CheckBox)item.FindControl("chkIsCandidateSelected");
string str = txtMaxResumes.Text;
if (chkBox.Checked && string.IsNullOrEmpty(str))
{
ScriptManager.RegisterClientScriptBlock(Page, Page.GetType(), "alert", "getMessagetest('ShareaJob');", true);
}
}
}
ASP.NET:
<Columns>
<telerik:GridTemplateColumn UniqueName="chkSelect" lowFiltering="false">
<HeaderTemplate>
<asp:CheckBox ID="chkSelectAll" runat="server" OnClick="return SelectAllCandidates(this);" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkIsCandidateSelected" runat="server" OnClick="return CandidateRowChecked();" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged1"/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Max.Resume(s) can upload" HeaderStyle-HorizontalAlign="Center" ShowFilterIcon="false" AllowFiltering="false">
<ItemTemplate>
<asp:TextBox ID="txtMaxResumes" runat="server" CssClass="rgf_txt_area_l2" Text="3" Width="80px" MaxLength="2">
</asp:TextBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
JavaScript的:
function getMessagetest(entity) {
if (entity == 'ShareaJob') {
radalert("Please enter number !", 370, 150, "Alert");
}
}
答案 0 :(得分:0)
最后我得到了解决方案。感谢。
foreach (GridDataItem item in radGridSahreaJob.MasterTableView.Items)
{
CheckBox CheckBox1 = item.FindControl("chkIsCandidateSelected") as CheckBox;
TextBox TextBox1 = item.FindControl("txtMaxResumes") as TextBox;
string strTxtResumes = TextBox1.Text;
if (CheckBox1 != null && CheckBox1.Checked && string.IsNullOrEmpty(strTxtResumes))
{
hdnCheckBox.Value = "1";
}
}