S
Stephan Bour
Hi,
I need to validate a text box in a datagrid nested inside a datalist. All I
need is to validate that any text is entered in the textbox. However, a
requiredfieldvalidator would not do because I want to perform the validation
only on the datagrid rows where a check box is checked.
Part of the datagrid:
<asp:TemplateColumn HeaderText="C #">
<ItemTemplate>
<asp:TextBox Width="50" MaxLenght="5" TextMode="SingleLine" ID="Cnumber"
runat="server" />
<asp:CustomValidator id="CNumNotNull"
ControlToValidate="Cnumber"
Display="Static"
InitialValue=""
OnServerValidate = "Validate"
ErrorMessage="Please enter a C Number"
runat="server">
*
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelectInProgress" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
However, the "Validate" script doesn't appear to run:
void Validate (object source,
System.Web.UI.WebControls.ServerValidateEventArgs e) {
e.IsValid = false;
DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList.Items) {
GridHolder = NewListItem.FindControl("InProgressGrid") as DataGrid;
foreach (DataGridItem NewGridItem in GridHolder.Items) {
CheckBox chkSelectInProgress =
(CheckBox)NewGridItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGridItem.Cells[5].Controls[1];
if (chkSelectInProgress.Checked == true) {
String Test = e.Value;
if (Test.Length > 0) {
e.IsValid = true;
}
}
}
}
}
Any suggestions?
Thanks,
Stephan.
I need to validate a text box in a datagrid nested inside a datalist. All I
need is to validate that any text is entered in the textbox. However, a
requiredfieldvalidator would not do because I want to perform the validation
only on the datagrid rows where a check box is checked.
Part of the datagrid:
<asp:TemplateColumn HeaderText="C #">
<ItemTemplate>
<asp:TextBox Width="50" MaxLenght="5" TextMode="SingleLine" ID="Cnumber"
runat="server" />
<asp:CustomValidator id="CNumNotNull"
ControlToValidate="Cnumber"
Display="Static"
InitialValue=""
OnServerValidate = "Validate"
ErrorMessage="Please enter a C Number"
runat="server">
*
</asp:CustomValidator>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Select" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:CheckBox ID="chkSelectInProgress" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
However, the "Validate" script doesn't appear to run:
void Validate (object source,
System.Web.UI.WebControls.ServerValidateEventArgs e) {
e.IsValid = false;
DataGrid GridHolder;
foreach (DataListItem NewListItem in InProgressList.Items) {
GridHolder = NewListItem.FindControl("InProgressGrid") as DataGrid;
foreach (DataGridItem NewGridItem in GridHolder.Items) {
CheckBox chkSelectInProgress =
(CheckBox)NewGridItem.Cells[6].Controls[1];
TextBox CNumber = (TextBox)NewGridItem.Cells[5].Controls[1];
if (chkSelectInProgress.Checked == true) {
String Test = e.Value;
if (Test.Length > 0) {
e.IsValid = true;
}
}
}
}
}
Any suggestions?
Thanks,
Stephan.