Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > GridView and Validation Controls

Reply
Thread Tools

GridView and Validation Controls

 
 
AlBruAn
Guest
Posts: n/a
 
      10-10-2007
I have a GridView on my page that is populated via a call to a function in
another class. Within the GridView, I have three additional columns; one
contains a CheckBox, one contains a TextBox, and the other one contains a
Dropdown list. On the same page and inside the same <Div> as the GridView, I
have a RegularExpressionValidator control and a CustomValidator control, both
of which are disabled in the HTML code. Not knowing any other way of doing
it, I wrote a JavaScript function, entered into on the Submit button's
OnClientClick property, to loop through each row, stopping at the first row
in which the CheckBox is checked. At this point, I'm attempting to set the
TextBox as the ControlToValidate property of the RegExValidator and am
attempting to set the DropDown as being the ControlToValidate of the
CustomValidator control. Despite this and failing to enter anything matching
the RegEx expression in the TextBox and/or failing to select an item from the
DropDown, it appears neither of the validators are working. Page.IsValid
returns true and the function called by the Submit button's OnClick property
contines to execute on the server side.

Following are my two JavaScript validation helpers:
function validateCheckVoucherRequestGrid(val) {
grid =
document.getElementById('ctl00_ContentPlaceHolder1 _grdCheckVoucherRequest');
rowCount = grid.rows.length;
var rowCounter;
var index;
for (rowCounter = 1; rowCounter < rowCount; rowCounter++) {
index = rowCounter;
index += 1;
var fieldName =
'ctl00_ContentPlaceHolder1_grdCheckVoucherRequest_ ctl0' + index +
'_chkRequest';
var amountField =
'ctl00_ContentPlaceHolder1_grdCheckVoucherRequest_ ctl0' + index +
'_txtAmount';
var reasonField =
'ctl00_ContentPlaceHolder1_grdCheckVoucherRequest_ ctl0' + index +
'_ddlReasonCode';
if (document.getElementById(fieldName).checked == true) {
if (document.getElementById(amountField).value == "") {
var amountValidator =
document.getElementById('ctl00_ContentPlaceHolder1 _revVoucherAmount');
amountValidator.enabled = true;
return false;
break;
}
else
amountValidator.enabled = false;
}
if (document.getElementById(reasonField).text == 'HDRROW') {
var reasonValidator =
document.getElementById('ctl00_ContentPlaceHolder1 _cvReasonCode');
reasonValidator.controltovalidate = reasonField;
reasonValidator.enabled = true;
return false;
break;
}
else
reasonValidator.enabled = false;
}
}
}

function checkVoucherRequestReasonIsSelected(val) {
var rowCounter
var index
for (rowCounter = 1; rowCounter < rowCount; rowCounter++) {
index = rowCounter;
index += 1;
var fieldName =
'ctl00_ContentPlaceHolder1_grdCheckVoucherRequest_ ctl0' +
index + '_chkRequest';
if (document.getElementById(fieldName).checked == true) {
var reasonField =
= 'ctl00_ContentPlaceHolder1_grdCheckVoucherRequest_ ctl0' +
index
+ '_ddlReasonCode';
if (document.getElementById(reasonField).text == 'HDRROW') {
var reasonValidator = document.getElementById
('ctl00_ContentPlaceHolder1_cvReasonCode');
reasonValidator.controltovalidate = reasonField;
reasonValidator.enabled = true;
return false;
break;
}
}
}
}

Pertinent portions of my HTML are as follows:
<asp:TemplateField HeaderText="Voucher Amount" ControlStyle-Width="70px">
<ItemTemplate>
<asp:TextBox ID="txtAmount" runat="server" />
<ajaxToolkit:MaskedEditExtender ID="meeVoucherAmount"
runat="server" Mask="999,999.99" MaskType="Number"
TargetControlID="txtAmount" InputDirection="RightToLeft"
PromptCharacter=" " />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:TemplateField>
<asp:TemplateField headertext="Voucher Reason">
<ItemTemplate >
<aspropDownList id="ddlReasonCode" runat="server" Width="300px">
</aspropDownList>
</ItemTemplate>
<ItemStyle Width="300px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Request Voucher">
<ItemTemplate>
<asp:CheckBox ID="chkRequest" Checked="false" runat="server" />
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" Width="70px" />
</asp:TemplateField>

<asp:RegularExpressionValidator ID="revVoucherAmount" runat="server"
EnableClientScript="true" Enabled="false" ValidationExpression=
"^\d+(\.\d\d)?$" ControlToValidate="txtToDate" ErrorMessage="Please enter
Voucher Amount requested for any selected Voucher Request(s) submitted."
/>
<asp:CustomValidator ID="cvReasonCode" runat="server"
EnableClientScript="true" Enabled="false" ControlToValidate="txtToDate"
ClientValidationFunction="checkVoucherRequestReaso nIsSelected();"
ErrorMessage="Please select a Request Reason for any Voucher Request(s)
submitted." />
<asp:Button ID="btnSubmitRequests" runat="server" Text="Submit Request(s)"
OnClientclick="validateCheckVoucherRequestGrid();"
OnClick="SubmitRequests_Click" />

My code-behind is as follows:
Protected Sub SubmitRequests_Click(ByVal sender As Object, ByVal e As
EventArgs)
Dim requestGrid As GridView = CType(grdCheckVoucherRequest, GridView)
Dim retVal As Boolean = True

If Page.IsValid Then
' Process data in grid and store it in the database
End If
End Sub

As I see it, this checks only the first row in which the CheckBox is checked
which would result in it being the only row checked; any other rows within
the GridView whose CheckBox may be checked will never be verified. What is
there I can do to ensure all rows that are checked have TextBox entries
matching the RegEx expression for them and that all of them also have a
selection made from the corresponding DropDown list?

Many thanks!

Allen B. Anderson
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Gridview & Validation Controls Kat ASP .Net Datagrid Control 1 04-09-2007 01:17 PM
GridView Hierarchical View - Gridview in Gridview =?Utf-8?B?bWdvbnphbGVzMw==?= ASP .Net 1 05-09-2006 06:48 PM
where is the validation occurs for validation controls baroque Chou ASP .Net 4 01-24-2006 03:32 PM
Page appears to fail validation even though it has no validation controls =?Utf-8?B?ZGh1cndpdHo=?= ASP .Net 1 04-10-2004 07:37 AM
ASP.NET Web Forms Validation Controls are Server-Side or Client-Side Validation? Matt ASP .Net 14 01-30-2004 09:15 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57