Click here to Skip to main content
15,910,981 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I've one list view control with
<LayoutTemplate> and <ItemTemplate>

in Item Template there are various textboxes

from this ListView user will select some rows and click on the button Go....

on this btn Click I want to validate with Required Field Validator to text boxes present only in these Selected row(s)...

Please provide any tricks or logic u have...........!
Posted
Updated 11-Oct-13 0:21am
v2
Comments
[no name] 11-Oct-13 6:29am    
Just put the validation group.
prashantttt 11-Oct-13 7:09am    
I've already given validation group bt its not working.........
Azee 11-Oct-13 6:38am    
How are you selecting the ListView rows? CheckBoxes?
prashantttt 11-Oct-13 7:08am    
yess with checkboxesss

1 solution

Hey there,

What I understand from your description, you want to validate only those textboxes where row is selected. Here are a few steps you need to follow.

1. Add RequiredFieldValidator for individual TextBoxes of the row (I think you have already done that), and set its Enabled = "false" and ValidationGroup=""

2. Second, Add a ValidationGroup = "YourValidationGroupName" for your Button.

3. Add OnCheckedChanged event for the CheckBoxes and Set AutoPostBack="true"

4. Here is what you need to do inside the OnCheckedChanged event:
- Find all the RequiredFieldValidator controls for each TextBox of the selected row and set Enabled="true" and ValidationGroup="YourValidationGroupName"
Here is the sample code:
C#
protected void checkbox1_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chk = sender as CheckBox;
            if (chk != null)
            {
                ListViewDataItem item = chk.NamingContainer as ListViewDataItem;
                if (item != null)
                {
                    RequiredFieldValidator RFV1 = item.FindControl("RequiredFieldValidator1") as RequiredFieldValidator;
                    if (RFV1 != null)
                    {
                        RFV1.Enabled = chk.Checked;
                        if (chk.Checked)
                            RFV1.ValidationGroup = "YourValidationGroupName";
                        else
                            RFV1.ValidationGroup = "";
                    }

                    RequiredFieldValidator RFV2 = item.FindControl("RequiredFieldValidator2") as RequiredFieldValidator;
                    if (RFV2 != null)
                    {
                        RFV2.Enabled = chk.Checked;
                        if (chk.Checked)
                            RFV2.ValidationGroup = "YourValidationGroupName";
                        else
                            RFV2.ValidationGroup = "";
                    }
                    //Do the same for remaining RequiredFieldValidators
                }
            }
        }


Let me know if it helps.

Azee...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900