Problem empty data check validation of rad listbox...

2 posts, 0 answers
  1. Nikunj
    Nikunj avatar
    4 posts
    Member since:
    Mar 2011

    Posted 14 Jun 2011 Link to this post

    Design Source Code:
     <telerik:RadGrid ID="radgridencounterdtls" runat="server" AutoGenerateColumns="false"
                AllowPaging="true" PageSize="5" Skin="Default" GridLines="None" CellPadding="0"
                CellSpacing="0"
                   PagerStyle-AlwaysVisible="true"
                    OnItemDataBound="radgridencounterdtls_ItemDataBound"
                  onupdatecommand="radgridencounterdtls_UpdateCommand"
                  onneeddatasource="radgridencounterdtls_NeedDataSource"
                  onitemcommand="radgridencounterdtls_ItemCommand">
                <MasterTableView DataKeyNames="ID,Tabs,Tabsname">
                    <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
                    <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </RowIndicatorColumn>
                    <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
                        <HeaderStyle Width="20px"></HeaderStyle>
                    </ExpandCollapseColumn>
                    <Columns>
                     <telerik:GridTemplateColumn HeaderText="Template Name"  UniqueName="TemplateName"  >
                            <ItemTemplate>
                                <asp:Label ID="lblTemplateTypeid" runat="server" Text='<%# Eval("TemplateName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                            <asp:Label ID="lbleditTemplateTypeid" runat="server" Text='<%# Eval("TemplateName") %>'></asp:Label>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="Role" UniqueName="RoleName"  >
                            <ItemTemplate>
                                <asp:Label ID="lblRoleID" runat="server" Text='<%# Eval("RoleName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                             <asp:Label ID="lbleditRoleID" runat="server" Text='<%# Eval("RoleName") %>'></asp:Label>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="Location"  UniqueName="Locationname"   >
                            <ItemTemplate>
                                <asp:Label ID="lblLocationID" runat="server" Text='<%# Eval("Locationname") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                            <asp:Label ID="lbleditLocationID" runat="server" Text='<%# Eval("Locationname") %>'></asp:Label>
                            </EditItemTemplate>
                    </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="Department"  UniqueName="DepartmentName">
                            <ItemTemplate>
                                <asp:Label ID="lbldepartmentId" runat="server" Text='<%# Eval("DepartmentName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                              <asp:Label ID="lbleditdepartmentId" runat="server" Text='<%# Eval("DepartmentName") %>'></asp:Label>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="Physician" UniqueName="PhysicianName" >
                            <ItemTemplate>
                                <asp:Label ID="lblPhysicianID" runat="server" Text='<%# Eval("PhysicianName") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                             <asp:Label ID="lbleditPhysicianID" runat="server" Text='<%# Eval("PhysicianName") %>'></asp:Label>
                           
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn HeaderText="Tabs" UniqueName="Tabsname" HeaderStyle-HorizontalAlign="Left"  EditFormColumnIndex="4"   HeaderStyle-VerticalAlign="Top" >
                            <ItemTemplate>
                                <asp:Label ID="lblTabs" runat="server" Text='<%# Eval("Tabsname") %>' Font-Bold="false" Font-Size="Smaller" Width="200"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                            <div>
                              <span style="float:left;"><telerik:RadListBox ID="rdlistbxEditEnctr" runat="server" Height="150px" SelectionMode="Multiple"  Width="230px" TransferMode="Copy"                                  AllowTransfer="true" TransferToID="rdlistbxEditselectedEnctr" EmptyMessage="No Record Found" CausesValidation="false" >
                             </telerik:RadListBox></span>
                             <span style="float:left;">
                             <telerik:RadListBox ID="rdlistbxEditselectedEnctr" runat="server" AllowReorder="true"
                                   EmptyMessage="No Record Selected"
                                  Height="150px"  Width="200px"  SelectionMode="Multiple"  CausesValidation="true"  >
                            </telerik:RadListBox>
                          <asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="*Required"
    ClientValidationFunction = "ValidateListBox" ValidationGroup="editenctr" >*Required</asp:CustomValidator>
     
                            </span>      
                              
                            </div>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                     <telerik:GridTemplateColumn>
                            <ItemTemplate>
                              <div style="color:#E75B18;"><span>
                                  <asp:LinkButton ID="lnkbtnedit" CommandArgument='<%# Eval("ID") %>' ForeColor="#E75B18" CommandName="Edit" runat="server">Edit</asp:LinkButton>/   <asp:LinkButton ID="lnkbtndelete" runat="server" CommandArgument='<%# Eval("ID") %>'  ForeColor="#E75B18" CommandName="delete"  OnClientClick="return delete_click();" Text="Delete"></asp:LinkButton>  </span></div>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <EditFormSettings ColumnNumber="6"  EditColumn-HeaderStyle-ForeColor="#E75B18"    >
                        <FormCaptionStyle   ForeColor="#E75B18"  HorizontalAlign="Left" />
                    </EditFormSettings>
                </MasterTableView>
                <FilterMenu EnableImageSprites="False">
                </FilterMenu>
                <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Web20">
                </HeaderContextMenu>
                <ValidationSettings CommandsToValidate="Update" EnableValidation="true" ValidationGroup="editenctr" />
            </telerik:RadGrid>

    Javascript code:
     function ValidateListBox(sender, args) {
                 var gridvw = document.getElementById("<%=radgridencounterdtls.ClientID%>");
           
              var options = gridvw.getElementsByTagName("select");
             if (options.length > 0) {
                  args.IsValid = true;
            }
            else {
               args.IsValid = false;
             }      


    Hi, I am facing  a problem to check empty radlist box in radgrid edititem template using custom validation. I have used above  javascript code and have validation is working properly...i have mentioned  radlistbox and its related custom validator  above context ("rdlistbxEditselectedEnctr " & "CustomValidator")
  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1596 posts

    Posted 16 Jun 2011 Link to this post

    Hi Michael,
    <telerik:RadListBox runat="server" ID="RadListBox1" AllowTransfer="true" TransferToID="RadListBox2">
                                  <Items>
                                      <telerik:RadListBoxItem Text="Item1" />
                                      <telerik:RadListBoxItem Text="Item2" />
                                      <telerik:RadListBoxItem Text="Item3" />
                                  </Items>
                              </telerik:RadListBox>
                              
                              <telerik:RadListBox runat="server" ID="RadListBox2">
                                  <Items>
                                  </Items>
                              </telerik:RadListBox>
                               
                              <asp:RequiredFieldValidator runat="server" ID="RequiredFieldValidator" ControlToValidate="RadListBox1"
                                  ErrorMessage="ErrorMessage">
                              </asp:RequiredFieldValidator>


    RadListBox is not rendered in the browser as a Select element, so you cannot find it using getElementByTagName. I suggest that you use RequiredFieldValidator instead of CustomValidator like this:




    Regards,
    Genady Sergeev
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top