Cannot use RequiredFieldValidator for CheckBoxList within datalist

I have a problem on using RequiredField Validator for CheckBoxList inside Datalist. I am using checkboxlist for poll options. I want the user to answer required poll questions. If user doesn't answer, I want to show an error message. Can anyone please help me to do this?

Here is my design:

     <div id="divPollDataList">
     <asp:DataList ID="PollDataList" runat="server" 
                 <asp:HiddenField ID="PollIDReqHiddenField" Value='<%# Eval("PollID") %>' runat="server" Visible="false" />
                 <asp:Label ID="lblReqQuestionNumber" runat="server" Text='<%# Eval("No of PollQuestion") %>' Font-Bold="true"></asp:Label>
                <asp:Label ID="lblRequiredPollQusetion" runat="server" Text='<%# Eval("PollQuestions") %>' Font-Bold="true"></asp:Label>
                <asp:HiddenField ID="HiddenFieldPollOption" runat="server" Value='<%# Eval("PollOptions") %>' Visible="false" />
                <asp:HiddenField ID="HiddenFieldPollType" runat="server" Value='<%# Eval("PollType") %>' Visible="false"/>
               <asp:RequiredFieldValidator ID="RequiredFieldValidatorReqPoll" runat="server"  CausesValidation="true" ControlToValidate="CheckBoxListMultiple"  Display="Dynamic" ErrorMessage="You must provide the feedback" ></asp:RequiredFieldValidator>
                  <asp:CheckBoxList ID="CheckBoxListMultiple" runat="server" ></asp:CheckBoxList>

       <asp:Button ID="btnSubmitPoll" runat="server" CausesValidation="true" Text="Submit"  OnClick="btnSubmitPoll_click"  />   


    <asp:Button ID="btnBindData" runat="server" Text="Bind" 
        onclick="btnBindData_Click" />

Here is my code:

   protected void PollDataList_ItemDataBound(object sender, DataListItemEventArgs e)
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            System.Data.DataRowView drv = (System.Data.DataRowView)(e.Item.DataItem);

            string strPollID = drv.Row["PollID"].ToString();
            string pollOptions = drv.Row["PollOptions"].ToString();
            string strPollType = drv.Row["PollType"].ToString();
            string strPollRequiredorNot = drv.Row["RequiredPoll"].ToString();

                CheckBoxList chkList = (CheckBoxList)e.Item.FindControl("CheckBoxListMultiple");
                foreach (string opt in pollOptions.Split('}'))
                var validator = (RequiredFieldValidator)e.Item.FindControl("RequiredFieldValidatorReqPoll");
                validator.Enabled = true;


You can read this article it's very interessant about Validator and CheckBoxList.

You can develop custom validator

public class RequiredFieldValidatorForCheckBoxList : BaseValidator

RadioButtonList can be validated , but not CheckBoxList

Link :

Need Your Help

Entity versus Model

java model-view-controller model entity

I was tidying up some classes in my package and realised every one of them was either directly annotated @Entity or was attached to one (I'm using Morphia). It occurred to me tha...

ASP MVC on IIS6 iis-6

In our asp mvc application, we are using embedded views, images and css files.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.