GRID Drop Down Column problem

6 posts, 0 answers
  1. Kannan
    Kannan avatar
    38 posts
    Member since:
    Dec 2010

    Posted 22 Jan 2011 Link to this post

    Hi,

    I have GridDropDownColumn with EnableEmptyListItem = "true" EmptyListItemValue="0" EmptyListItemText="Select" in my RadGrid and required field validator as well and i am experiencing a problem that my validator is not fired when the drop down selected text is "Select". I have many fields as well in an order (ie) For Ex. User Name, Password, User Type and Contact No etc., in this User Type is the drop down list. The required field validator is fired for username, password,contact no and for user type its not firing. So i used to check the separately OnInsertCommand.

    But I required is the required field validator should fire that. So i need some help in this regards

    Thanks,
    Kannan
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Jan 2011 Link to this post

    Hello Kannan,

    This is the code that I tried in my application. Please check this and find whether you have missed anything.

    ASPX:
    <telerik:GridDropDownColumn ListTextField="UserType" ListValueField="UserType"
               DataField="UserType" DropDownControlType="DropDownList"
               UniqueName="GridDropDownColumn2"
               DataSourceID="SqlDataSource1" EnableEmptyListItem="true" EmptyListItemValue="0"
               EmptyListItemText="Select" >
    </telerik:GridDropDownColumn>

    C#:
    protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
       {
           if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
           {
               GridEditFormInsertItem insertItem = e.Item as GridEditFormInsertItem;
               DropDownList dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as DropDownList;
               GridDropDownColumnEditor editor = (GridDropDownColumnEditor)insertItem.EditManager.GetColumnEditor("GridDropDownColumn2");
               TableCell cell = (TableCell)editor.ContainerControl;
              
               RequiredFieldValidator validator = new RequiredFieldValidator();
               validator.ControlToValidate = dropDownList1.ID;
               validator.InitialValue = "0";
               validator.ErrorMessage = "*";
               cell.Controls.Add(validator);
            }
       }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Kannan
    Kannan avatar
    38 posts
    Member since:
    Dec 2010

    Posted 24 Jan 2011 Link to this post

    Hi Princy,

    Thanks for your code and I have missed out validator.InitialValue = "0";

    Now its working fine.

    Thanks & Regards
    Kannan.S
  5. Carl
    Carl avatar
    4 posts
    Member since:
    Apr 2014

    Posted 05 Dec 2014 Link to this post

    I'm working on a similar project using RadGrid with GridDropDownColumns and EnableEmptyListItem options. I'm trying to implement a solution like the one proposed by Princy but I was wondering if I could accomplish the same thing with a RadComboBox instead of the ASP.NET DropDownList control? I tried to change:

    DropDownList dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as DropDownList;
    to
    RadComboBox dropDownList1 = insertItem["GridDropDownColumn2"].Controls[0] as RadComboBox;

    However, now the validator will not fire, but it works correctly if I use DropDownList instead of RadCombBox.


    Please advise if this is a supported scenario or if I must use DropDownList instead.

    Thanks.
  6. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1800 posts

    Posted 10 Dec 2014 Link to this post

    Hi Carl,

    The only difference when RadComboBox control is used is that the InitialValue of the validator must be set to "Select" instead of "0":
    validator.InitialValue = "Select";

    Additionally, I would like to point out that you can accomplish the same behavior from the markup only:
    <telerik:GridDropDownColumn ListTextField="CompanyName" ListValueField="CompanyName"
        DataField="CompanyName" DropDownControlType="RadComboBox" UniqueName="GridDropDownColumn2"
        DataSourceID="SqlDataSource1" EnableEmptyListItem="true" EmptyListItemValue="0"
        EmptyListItemText="Select">                    
        <ColumnValidationSettings EnableRequiredFieldValidation="true">
            <RequiredFieldValidator ValidateRequestMode="Enabled" InitialValue="Select" ErrorMessage="*"></RequiredFieldValidator>
        </ColumnValidationSettings>
    </telerik:GridDropDownColumn>

    Hope this helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  7. Carl
    Carl avatar
    4 posts
    Member since:
    Apr 2014

    Posted 10 Dec 2014 in reply to Konstantin Dikov Link to this post

    Excellent! I was able to swap to using RadComboBox for my grid editors successfully, thanks for the help.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017