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

required validator problem in grid

4 Answers 87 Views
Grid
This is a migrated thread and some comments may be shown as answers.
adam
Top achievements
Rank 1
adam asked on 14 Aug 2013, 07:50 PM
I have a requiredfieldvalidator for a raddropdownlist in a radgrid and it will not fire in editmode or insert.  The other requried validators in the grid are firing, but this one doesn't want to work.  What is the problem?  Here is the code-

 <telerik:GridTemplateColumn HeaderStyle-Width="200px" HeaderText="Fund" UniqueName="fund_id_fk"
                            DataField="fund_id_fk">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblFund" Width="200px" Text='<%# Eval("unit_ep_funds.fund_name") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDropDownList runat="server" ID="FundIDDropDown" DataValueField="fund_id"
                                    SelectedValue='<%# Bind("fund_id_fk") %>' DataTextField="fund_name" DataSourceID="EntityDataFunds"
                                    AppendDataBoundItems="true">
                                    <Items>
                                        <telerik:DropDownListItem Text="Select a fund" Value="-1" />
                                    </Items>
                                </telerik:RadDropDownList>
                                <asp:RequiredFieldValidator InitialValue="-1" ID="RequiredFieldValidator11" ControlToValidate="FundIDDropDown"
                                    ErrorMessage="**Required" runat="server">
                                </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>

4 Answers, 1 is accepted

Sort by
0
adam
Top achievements
Rank 1
answered on 14 Aug 2013, 08:21 PM
The asp.net dropdownlist with validator DOES WORK.  So why is raddropdownlist with validator not firing like it should?

 <telerik:GridTemplateColumn HeaderStyle-Width="200px" HeaderText="Fund" UniqueName="fund_id_fk"
                            DataField="fund_id_fk">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblFund" Width="200px" Text='<%# Eval("unit_ep_funds.fund_name") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <asp:DropDownList runat="server" ID="FundIDDropDown2" DataValueField="fund_id" DataTextField="fund_name"
                                    DataSourceID="EntityDataFunds" AppendDataBoundItems="true">
                                    <asp:ListItem Text="Select a fund" Value="-1"></asp:ListItem>
                                </asp:DropDownList>
                                <asp:RequiredFieldValidator InitialValue="-1" ID="RequiredFieldValidator11" ControlToValidate="FundIDDropDown2"
                                    ErrorMessage="**Required" runat="server">
                                </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
0
A2H
Top achievements
Rank 1
answered on 14 Aug 2013, 11:49 PM
Hi Adam,

Please remove the “ InitialValue”  property from RequiredFieldValidator

Please use the modified code

<telerik:GridTemplateColumn HeaderStyle-Width="200px" HeaderText="Fund" UniqueName="fund_id_fk"
                            DataField="fund_id_fk">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lblFund" Width="200px" Text='<%# Eval("unit_ep_funds.fund_name") %>'></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadDropDownList runat="server" ID="FundIDDropDown" DataValueField="fund_id"
                                    SelectedValue='<%# Bind("fund_id_fk") %>' DataTextField="fund_name" DataSourceID="EntityDataFunds"
                                    AppendDataBoundItems="true">
                                    <Items>
                                        <telerik:DropDownListItem Text="Select a fund" Value="-1" />
                                    </Items>
                                </telerik:RadDropDownList>
                                <asp:RequiredFieldValidator  ID="RequiredFieldValidator11" ControlToValidate="FundIDDropDown"
                                    ErrorMessage="**Required" runat="server">
                                </asp:RequiredFieldValidator>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>


Thanks,
A2h
0
adam
Top achievements
Rank 1
answered on 15 Aug 2013, 06:57 PM
Hi A2H,

Unfortunately, that didn't work either. This might need to be submitted as bug.

Due to time constraints, I'm going to use the asp.net dropdownlist w/ validator for this scenario. 

Thanks,
Adam 
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2013, 09:04 AM
Hi Adam,

You can try setting the DefaultMessage of the RadDropDownList,rather than adding the DropDownListItem.Please try the following code snippet.

ASPX:
<telerik:GridTemplateColumn HeaderText="ShipCity" UniqueName="ShipCity" DataField="ShipCity">
    <ItemTemplate>
        <asp:Label runat="server" ID="lblShipCity"  Text='<%# Eval("ShipCity") %>'></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadDropDownList runat="server" ID="DropDown1" DataValueField="ShipCity"
            CausesValidation="true" DefaultMessage="Select a ShipCity" SelectedValue='<%# Bind("ShipCity") %>'
            DataTextField="ShipCity" DataSourceID="SqlDataSource2" >
        </telerik:RadDropDownList>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="DropDown1"
            ErrorMessage="**Required" runat="server">
        </asp:RequiredFieldValidator>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

Thanks,
Princy
Tags
Grid
Asked by
adam
Top achievements
Rank 1
Answers by
adam
Top achievements
Rank 1
A2H
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or