This is a migrated thread and some comments may be shown as answers.

How to Enable Required Field Validator in Edit Mode not Insert Mode based on another column data

3 Answers 478 Views
Grid
This is a migrated thread and some comments may be shown as answers.
gc_0620
Top achievements
Rank 1
gc_0620 asked on 14 Aug 2009, 08:36 PM

Folks,

I have a RadGrid (RadGrid1) with 2 Template coulmns, Unique Name "Fulltime" and  "Division" . I would like to see if RadGrid is in Edit Mode and Value of Column "Fulltime"   = "Yes"  then Required Field Validator ="RequiredFieldValidator1" will be activated else not.
Another way, if RadGrid is in Insert Mode then Column Division is not required but it is in Edit Mode and Column "Fulltime"   = "Yes", then Column Division is required.  I do not see Insert Temple options in Rad Grid. Below is my code.

I am using RadControls for ASP.NET AJAX Q2 2009 NET35 with VS 2008. Any help will be appreciated. Thanks.

_________________ 

<telerik:GridTemplateColumn
        DataField="Fulltime" HeaderText="Full time"
            SortExpression="Fulltime" UniqueName="Fulltime" Visible = "True" > 
        <ItemTemplate>  
         <asp:Label ID="LblEmploymentStatus" runat="server" Text='<%#Eval("Fulltime") %>'></asp:Label>  
    </ItemTemplate> 
    <EditItemTemplate>
    <telerik:RadComboBox ID="RadComboBox1" Runat="server" Text = '<%#Bind("Fulltime") %>'>
            <Items>
                <telerik:RadComboBoxItem runat="server" Selected="True" Text="Yes"
                    Value="Yes" />
                <telerik:RadComboBoxItem runat="server" Text="No" Value="No" />
            </Items>
        </telerik:RadComboBox>
    </EditItemTemplate>
   
        </telerik:GridTemplateColumn>

 

<telerik:GridTemplateColumn UniqueName="Division" HeaderText="Division" SortExpression="Division"  > 
        <ItemTemplate>  
         <asp:Label ID="LblDivision" runat="server" Text='<%#Eval("Division") %>'></asp:Label>  
    </ItemTemplate> 
    
    <EditItemTemplate>    
         <asp:TextBox ID="EditDivision" Text='<%#Bind("Division") %>' runat="server"></asp:TextBox>  
         <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="EditDivision"
                                    ErrorMessage="* Required"  Display ="Dynamic"   runat="server">
                                </asp:RequiredFieldValidator>          
    </EditItemTemplate>  
      </telerik:GridTemplateColumn>

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 17 Aug 2009, 10:56 AM
Hello gc_0620,

You can hide the validation control if GridTableView.IsItemInserted is false. For more info I suggest you to check this example where we have used similar technique for the command item:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx

Regards,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
gc_0620
Top achievements
Rank 1
answered on 18 Aug 2009, 12:36 AM
Vlad,

I think you misunderstood me. I want to check:

If Rad Grid is in Insert/Edit Mode. 

1) If Rad Grid is in Insert Mode, Column Division is not required.

2) If Rad grid is in Edit Mode and column  Fulltime   = "Yes",  then dynamically (i.e in Run time) create a RequiredFieldValidator (i.e. RequiredFiledValidator1) for Column Division. 

I mean RequiredFieldValidaor1 will Validate the Control Division only if RadGrid is in Edit Mode and Value of Column Fulltime = "Yes".

______________

I want also to clarify I am using Custom Command Item Templates not inline Edit Command (i.e. not using GridEditCommandColumn). Below is my CommanditemTemplate (similar to : http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx). Thanks

 <CommandItemTemplate>
                    <div style="padding: 5px 5px;">
                        Custom command item template&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />Edit selected</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" />Update</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" />Cancel editing</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/AddRecord.gif" />Add new</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Insert.gif" /> Add this Customer</asp:LinkButton>&nbsp;&nbsp;
<asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected customers?')"
runat="server" CommandName="DeleteSelected"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Delete.gif" />Delete selected customers</asp:LinkButton>&nbsp;&nbsp;

                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Refresh.gif" />Refresh customer list</asp:LinkButton>
                    </div>
                </CommandItemTemplate>

0
Vlad
Telerik team
answered on 18 Aug 2009, 06:10 AM
Hi,

Indeed to check if the grid is in insert mode you should use IsItemInserted.


All the best,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
gc_0620
Top achievements
Rank 1
Answers by
Vlad
Telerik team
gc_0620
Top achievements
Rank 1
Share this question
or