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:
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 = "";
}
}
}
}
Let me know if it helps.
Azee...