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

Enable\disable requiredfield validator on PerformInsert command of grid

3 Answers 409 Views
Grid
This is a migrated thread and some comments may be shown as answers.
pavan
Top achievements
Rank 1
pavan asked on 15 Dec 2010, 01:12 PM

 

 

 I have a RadGrid that uses a GridTemplate column along with two Gridbutton columns called Edit and Delete and one link to ADD NEW RECORD.When I click on 'add new record' link  to enter new record.In insert mode,treeview along with some textboxes get displayed with validation.What I want that onclick of Save button,it validate all textboxes along with treeview if it is enabled otherwise it should validate only textboxes.On 'PerformInsert' command ,I try to enable or disable that validator depending on the status of treeview.but it is not working.I try to change the Validation group also but still it is not working.

 

<telerik:RadGrid ID="radgridUserMgt" GridLines="None" runat="server" AllowAutomaticDeletes="true" AllowAutomaticInserts="false"                     AllowAutomaticUpdates="false" AllowSorting="true"  AutoGenerateColumns="false" OnSortCommand="radgridUserMgt_SortCommand"  OnItemCommand="radgridUserMgt_ItemCommand">
    <mastertableview commanditemdisplay="TopAndBottom" datakeynames="UserID"   itemstyle-horizontalalign="Left" alternatingitemstyle-horizontalalign="Left"
     autogeneratecolumns="false" editmode="EditForms" insertitemdisplay="Top">
        <ItemStyle Font-Size="11px" />                        <AlternatingItemStyle Font-Size="11px" />  
 <Columns>                                                                 <telerik:GridTemplateColumn HeaderText="Email" UniqueName="Email" SortExpression="Email"                                                            ColumnEditorID="EmailColumnEditor" DataField="Email" >
  <ItemTemplate>
    <asp:Label runat="server" ID="lblEmail" Text='<%# AntiXss.HtmlEncode(Eval("Email").ToString())%>'></asp:Label>
  </ItemTemplate>
   <EditItemTemplate>
   <asp:TextBox MaxLength="100" runat="server" ID="txtEmail" Width="100px" Text='<%# Bind("Email") %>' ></asp:TextBox><span
  style="color: Red ;"><asp:RequiredFieldValidator ID="valReqFieldEmail" ControlToValidate="txtEmail"   ErrorMessage="*" runat="server"  Width="10px" ValidationGroup="ValidationGrp1" >   </asp:RequiredFieldValidator><br />
  </EditItemTemplate>                                                        </telerik:GridTemplateColumn>
                                                          
                                                        <telerik:GridTemplateColumn HeaderText="Business Email" UniqueName="BusinessEmail" SortExpression="BusinessEmail"
 ColumnEditorID="BusinessEmailColumnEditor" DataField="BusinessEmail" ItemStyle-Width="10px" >                                                            <ItemTemplate>                                                                <asp:Label runat="server" ID="lblBusinessEmail" Text='<%# AntiXss.HtmlEncode(Eval("BusinessEmail").ToString())%>'></asp:Label>                                                            </ItemTemplate>                                                            <EditItemTemplate>                                                                       <asp:TextBox MaxLength="100" runat="server" ID="txtBusinessEmail" Width="100px" Text='<%# Bind("BusinessEmail") %>' ValidationGroup="ValidationGrp1" ></asp:TextBox><span style="color: Red;"><br />
</EditItemTemplate>                                                        </telerik:GridTemplateColumn>
                                                          
                                                                                                                                         <telerik:GridTemplateColumn UniqueName="SelectPartner"                   HeaderText="Select Partner" Visible="false" ColumnEditorID="SelectPartnerColumnEditor">                                   <ItemTemplate>                                                                <asp:Label runat="server" ID="lblSelectPartner" Text="Select Partner"></asp:Label>
    </ItemTemplate>                                                            <EditItemTemplate>                                                            <span>                                                                <telerik:RadTreeView ID="radSelectPartner" runat="server" CheckBoxes="True" Height="150px"  TriStateCheckBoxes="true" CheckChildNodes="true" 
 OnLoad="radSelectPartner_Load"  ValidationGroup="ValidationGrp1">
                                                                </telerik:RadTreeView></span>                                                                    <asp:RequiredFieldValidator ID="valReqFieldSelectPartner" runat="server" ErrorMessage="*"     ControlToValidate="radSelectPartner"    Width="10px"  ValidationGroup="ValidationGrp1"   EnableClientScript="true">
    </asp:RequiredFieldValidator>                                                      </EditItemTemplate>                                                        </telerik:GridTemplateColumn>                                                        <telerik:GridButtonColumn HeaderText="Edit" CommandName="Edit" Text="Edit" ItemStyle-HorizontalAlign="Center"  ButtonType="ImageButton"  UniqueName="EditCommandColumn" ImageUrl="~/OneViewImages/edit.png">   </telerik:GridButtonColumn>  
<telerik:GridButtonColumn HeaderText="Delete" ButtonType="ImageButton"    Text="Delete User"  UniqueName="DeleteColumn" >
</telerik:GridButtonColumn>                                                      </Columns>                                                                         <EditFormSettings ColumnNumber="3"
                                                                                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="LightBlue" Width="100%" />                                                        <FormTableStyle CellSpacing="0" CellPadding="2" Height="80px" Width="100%" BackColor="LightBlue" />                                                        <FormTableAlternatingItemStyle Wrap="False" ></FormTableAlternatingItemStyle>
   <EditColumn ButtonType="ImageButton" InsertText="Add User" UpdateText="Update" UniqueName="EditCommandColumn1"   CancelText="Cancel" >                 </EditColumn>                                                        <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle>
   </EditFormSettings>                                                </mastertableview>                                                <ValidationSettings CommandsToValidate="PerformInsert,Update" ValidationGroup="ValidationGrp1"  />

Any help will be appreciated.its urgent
Thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 15 Dec 2010, 01:40 PM
Hello Pavan,

Try to enable/disable the RequiredFieldValidator in ItemDataBound event like below.

C#:
protected void radgridUserMgt_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
        //if the item is in insert mode
        {
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
            if()//your condition
            RequiredFieldValidator validator1 = (RequiredFieldValidator)insertItem.FindControl("valReqFieldSelectPartner");
            validator1.Enabled = false;
        }
    }

Thanks,
Princy.
0
pavan
Top achievements
Rank 1
answered on 15 Dec 2010, 02:36 PM
still it is not validating when radtreeview is enabled.
0
pavan
Top achievements
Rank 1
answered on 15 Dec 2010, 03:52 PM
when I changed the validation group in Databound event .it validates radtreeview when none of the node is selected but when we select some node,still error message get displayed.
In aspx page,radtreeview and its requiredfield validator is assigned differen validation group(ValidationGrp2) what I have assigned to other textboxes(ValidationGrp1).Then in databound event I am assigning both radtreeview and requiredfield validator as ValidationGrp1 when radtreeview is enabled. So that these can also be validated.And Same changes are done in OnSelectedIndexedChanged event of radcombo box whose selection make radtreeview as enable or disable.and in grid  I used below setting
<ValidationSettings CommandsToValidate="PerformInsert,Update" ValidationGroup="ValidationGrp1" />
Tags
Grid
Asked by
pavan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
pavan
Top achievements
Rank 1
Share this question
or