I have one datalist inside there is one radiobuttonlist and item binding from database. in radiobuttonlist there are three Item binded Approved,N/A and Rejected.
for image please go to this link... http://stackoverflow.com/questions/35313639/how-can-we-validate-radiobuttonlist-inside-datalist-based-on-item
so what do i want when user click on Update button and if they are going to approve then all fileds(suppose there are 10 record binding) should be mandatory to checked.
I want to validate all Approve Item on Button click not N/A or Reject.Please suggest me how can i achive this task. ..Here is some code that i have written it's working fine but also asking for Reject button when i click on second record and leaving first as null.
int sum = 0;
foreach (DataListItem item in dtLstRejection.Items)
{
RadioButtonList rdlReasoncodeType ((RadioButtonList)item.FindControl("rdlReasonType"));
System.Web.UI.WebControls.Label lbldlmsg = (Label)item.FindControl("lbldlmsg");
{
if (rdlReasoncodeType.SelectedIndex == 0|| rdlReasoncodeType1.SelectedIndex== -1)
{
if (rdlReasoncodeType1.SelectedItem == null)
{
if (sum == 0)
{
lbldlmsg.Text = "*Approve fields are mandatory to check";
return; }}}}
else
{
sum++;
lbldlmsg.Text = "";
}
lbldlmsg.Text = "";
}}

ali tuncerPosted Feb 17, 2016, 3:37 AM
In other words, if it is not rejected, you need to validate? make sure approve or N/A is selected..
{
RadioButtonList rdlReasoncodeType = ((RadioButtonList)item.FindControl("rdlReasonType"));
System.Web.UI.WebControls.Label lbldlmsg = (Label)item.FindControl("lbldlmsg");
if (rdlReasoncodeType.SelectedIndex == -2) // if rejected no need to validate
{
break;
}
else if (rdlReasoncodeType.SelectedIndex == -1) // if nothing is selected need to validate
{
lbldlmsg.Text = "*Approve fields are mandatory to check";
}
else
{
lbldlmsg.Text = string.Empty;
}
}
imran azamPosted Feb 17, 2016, 2:05 AM
ali tuncerPosted Feb 14, 2016, 1:09 AM
I understand rdlReasoncodeType is the radiobuttonlist inside datalist, what is rdlReasoncodeType1? Do you have 2 radiobuttonlist?