Hi Telerik team;
I have a master grid and a detail grid in my aspx page. I have edit and insert set up in the detail grid. I have added required field validator in the code behind for the text box. I am running into an issue with validation happening on both edit and insert mode at the same time when any text is not entered in the text box in both the modes and any of the update or insert buttons are clicked. The grid allows both the edit and insert modes to be turned on at any time. I have attached a screen shot in order to help explain it better. Is there any way, that the validation could be performed only in edit or insert mode at any time or just to turn edit or insert mode only and not allow both of these to be enabled? I have also attached my code that I have for this.
Thanks in advance. Any help would be appreciated.
Meera
aspx page:
<telerik:RadGrid ID="viewGrid" runat="server" ActiveItemStyle-BorderColor="ActiveBorder" |
ShowStatusBar="True" AllowSorting="true" ItemStyle-BorderWidth="1px" OnSortCommand="viewGrid_Sort" |
MasterTableView-ExpandCollapseColumn-CollapseImageUrl="~/App_Themes/Images/Content/collapse.gif" |
MasterTableView-ExpandCollapseColumn-ItemStyle-CssClass="textalignleft" |
MasterTableView-ExpandCollapseColumn-ButtonType="ImageButton" |
MasterTableView-ExpandCollapseColumn-ExpandImageUrl="~/App_Themes/Images/Content/expand.gif" |
OnUpdateCommand="viewGrid_UpdateCommand" Width="900px" |
MasterTableView-ExpandCollapseColumn-ItemStyle-HorizontalAlign="Center" OnItemCreated="viewGrid_ItemCreated" |
MasterTableView-ExpandCollapseColumn-ItemStyle-VerticalAlign="Middle" OnItemDataBound="viewGrid_DataBound" |
MasterTableView-ExpandCollapseColumn-ItemStyle-Width="2%" OnDetailTableDataBind="viewGrid_DetailTableDataBind" |
OnNeedDataSource="viewGrid_NeedDataSource" OnPreRender="viewGrid_PreRender" |
OnInsertCommand="viewGrid_InsertCommand" AllowMultiRowEdit="false"> |
<MasterTableView AutoGenerateColumns="False" HierarchyLoadMode="ServerBind" |
DataKeyNames="DomainName,ParentDomainValue" Name="Master" > |
<DetailTables> |
<telerik:GridTableView DataKeyNames="DomainName,ParentDomainName,ParentDomainValue,DomainValue" Name="DomainLabel" |
AutoGenerateColumns="false" BorderStyle="None" ItemStyle-BorderWidth="0px" AllowSorting="false" |
ShowHeader="false" Width="900px" |
CommandItemDisplay="Top" EditMode="InPlace"> |
<ParentTableRelation> |
<telerik:GridRelationFields DetailKeyField="DomainName" MasterKeyField="DomainName" /> |
</ParentTableRelation> |
<CommandItemSettings AddNewRecordText="<%$ Resources:DomainAdmin, locAddDomainValue %>" /> |
<Columns> |
<telerik:GridTemplateColumn UniqueName="DomainLabelcol" > |
<ItemTemplate> |
<asp:Label ID="plSubject" runat="server" Text="Domain Values"/> |
</ItemTemplate> |
<ItemStyle Width="150px" Wrap="false" HorizontalAlign="Left" CssClass="panelstyle" |
ForeColor="#62267f" Font-Bold="true"/> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn UniqueName="DomainValue" DataType="System.String" |
DataField="DomainValue" ColumnEditorID="GridTextBoxColumnEditor1" |
ItemStyle-HorizontalAlign="Left" |
ItemStyle-Wrap="false" |
ItemStyle-Width="300px"> |
</telerik:GridBoundColumn> |
<telerik:GridCheckBoxColumn DataField="ActiveFlag" UniqueName="ActiveFlag" |
DataType="System.Boolean" |
ItemStyle-HorizontalAlign="Left" |
ItemStyle-Wrap="false" |
ItemStyle-Width="20px"> |
</telerik:GridCheckBoxColumn> |
<telerik:GridTemplateColumn UniqueName="DomainLabelcol" > |
<ItemTemplate> |
<asp:Label ID="lblActive" Text="Active" runat="server" CssClass="ActiveLabelStyle" /> |
</ItemTemplate> |
<ItemStyle Width="130px" Wrap="false" HorizontalAlign="Left" /> |
</telerik:GridTemplateColumn> |
<telerik:GridEditCommandColumn ButtonType="ImageButton" |
EditImageUrl="../App_Themes/Images/Buttons/domain_pur_edit.gif" |
InsertImageUrl="../App_Themes/Images/Buttons/domain_gr_insert.gif" |
CancelImageUrl="../App_Themes/Images/Buttons/domain_gr_cancel.gif" |
UpdateImageUrl="../App_Themes/Images/Buttons/domain_gr_update.gif" |
UniqueName="EditDomainValueColumn" |
ItemStyle-HorizontalAlign="Right" |
ItemStyle-Wrap="false" |
ItemStyle-Width="200px"> |
</telerik:GridEditCommandColumn> |
<telerik:GridCheckBoxColumn DataField="EditableFlag" UniqueName="EditFlag" |
DataType="System.Boolean" Visible="false" > |
</telerik:GridCheckBoxColumn> |
</Columns> |
</telerik:GridTableView> |
</DetailTables> |
<Columns> |
<telerik:GridBoundColumn UniqueName="DomainName" DataType="System.String" HeaderText="<%$ Resources:DomainAdmin, locDomainName %>" |
DataField="DomainName" SortExpression="DomainName" |
ItemStyle-HorizontalAlign="Left" |
HeaderStyle-Width="200px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" |
HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="200px" |
SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png" |
SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png" |
> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="ParentDomainName" DataType="System.String" |
HeaderText="<%$ Resources:DomainAdmin, locParentDomainName %>" DataField="ParentDomainName" |
SortExpression="ParentDomainName" |
ItemStyle-HorizontalAlign="Left" |
HeaderStyle-Width="300px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" |
HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="300px" |
SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png" |
SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="ParentDomainValue" DataType="System.String" HeaderText="<%$ Resources:DomainAdmin, locParentDomainValue %>" |
DataField="ParentDomainValue" SortExpression="ParentDomainValue" |
ItemStyle-HorizontalAlign="Left" |
HeaderStyle-Width="300px" HeaderStyle-HorizontalAlign="Left" ItemStyle-Wrap="false" |
HeaderStyle-Font-Bold="true" HeaderStyle-ForeColor="#62267f" ItemStyle-Width="300px" |
SortAscImageUrl="~/App_Themes/Images/Buttons/arrow_sort_up.png" |
SortDescImageUrl="~/App_Themes/Images/Buttons/arrow_sort_down.png"> |
</telerik:GridBoundColumn> |
</Columns> |
<AlternatingItemStyle Wrap="false"/> |
<ItemStyle Wrap="false"/> |
<RowIndicatorColumn Visible="False"> |
<HeaderStyle Width="20px" /> |
</RowIndicatorColumn> |
<ExpandCollapseColumn ButtonType="ImageButton"> |
</ExpandCollapseColumn> |
<EditFormSettings> |
<PopUpSettings ScrollBars="None" /> |
</EditFormSettings> |
</MasterTableView> |
</telerik:RadGrid> |
code behind:
protected void viewGrid_ItemCreated(object sender, GridItemEventArgs e) |
{ |
if (e.Item.OwnerTableView.Name == "DomainLabel") |
{ |
//Add requiredfieldvalidator for insert and edit. |
if ((e.Item is GridEditableItem) && e.Item.IsInEditMode) |
{ |
GridEditableItem editItem = (GridEditableItem)e.Item; |
TextBox txtbx = (TextBox)editItem["DomainValue"].Controls[0]; |
txtbx.ID = "TextValidated"; |
RequiredFieldValidator reqfdvalidtr = new RequiredFieldValidator(); |
reqfdvalidtr.ID = "RequiredFieldValidator1"; |
reqfdvalidtr.ErrorMessage = "Required"; |
reqfdvalidtr.ControlToValidate = "TextValidated"; |
editItem["DomainValue"].Width = Unit.Pixel(100); |
editItem["DomainValue"].Controls.Add(reqfdvalidtr); |
} } } |