
After weeks of researching for answer, I finally came up with the solution of how to validate objects within a FormView using ASP.NET 2.0 programming language.
Assuming you have a FormView, and you require users to update information to the SQL database. There is a RadioButtonList and a TextBox. The entry within the textbox is optional, but it will be mandatory if one of the option is chosen. Take for example, the screen-shot below.

Task: To validate that the texbox is populated with information if the radio button selection is "Reject".
Procedure:
- From the Formview, specify the following command:
OnItemUpdating = "ValidateReject"
This is inserted in the line containing:
<asp:FormView ID=... OnItemUpdating="ValidateReject"...>
- Write the following C# code for ValidateReject:
protected void ValidateReject(object sender, FormViewUpdateEventArgs e)
{
FormViewRow row = MyFormView.Row;
RadioButtonList list = (RadioButtonList)row.FindControl("MyRadioButtonList");
string y1 = list.SelectedValue;
labelShow.Text = null;
if (y1 == "Reject")
{
TextBox Text1 = (TextBox)row.FindControl("textbox1");
string x1 = Text1.Text;
if (x1 == null || x1 == "")
{
labelShow.Text = "<font color=\"red\">Rejection Without Reasons!</font>";
e.Cancel = true;
}
else
labelShow.Text = null;
}
} - I have also included a text label to indicate the reason:
<asp:Label ID="labelShow" runat="server" />
With a few line of codes, you can easily validate any information from the FormView! In addition, this can also be extended to DetailsView as well!





























