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")
<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")