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

Bind GridDropDownColumn to a web service

7 Answers 212 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Roberto
Top achievements
Rank 2
Roberto asked on 09 Aug 2009, 05:44 AM
I have populated my grid with a service and everything works fine, now i want to populate a GridDropDownColumn with a WebService i think the GridDropDownColumn is a RadComboBox and i found a sample using the webservicesettings tag but i dont how to implement it for GridDropDownColumn.

I hope you can help me

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 11 Aug 2009, 12:43 PM
Hi Roberto,

The RadComboBox object should be accessible in RadGrid's ItemCreated event. If we are talking about RadComboBox in the edit form of the GridDropDownColumn, here is how you can access it:

void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
    { 
        GridEditableItem item = e.Item as GridEditableItem; 
        RadComboBox combo = (item.EditManager.GetColumnEditor("DropDownColumnNAme"as GridDropDownListColumnEditor).ComboBoxControl; 
        //you can now set combo.WebServiceSettings.Path 
    } 

Your combo now holds a reference to the actual RadComboBox control and you can set its properties programmatically.

Sincerely yours,
Veli
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
Roberto
Top achievements
Rank 2
answered on 11 Aug 2009, 07:00 PM

Thanks Veli,

probably you could help with this, i need a grid displaying my records with a column which links with a "catalog" for example this column called "Tipo" brings a "0" and i want to display the description of that zero for example "Beverages" an if it's bring a "1" i want to display "Food", so i think a DropdownColumn does this but it doesn't work

this is my grid:

 

 

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Black" AllowPaging="true" PageSize="10">  
                    <MasterTableView ClientDataKeyNames="Identificador">  
                        <PagerStyle Mode="NextPrev" /> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="Identificador" HeaderText="Identificador" Display="false" /> 
                            <telerik:GridBoundColumn DataField="Proyecto" HeaderText="Proyecto" Display="false" /> 
                            <telerik:GridBoundColumn DataField="Nombre" HeaderText="Estación" /> 
                             <telerik:GridDropDownColumn DataField="Tipo" HeaderText="Tipo de Estación" DataSourceID="odsTipoEstacion" 
                                ListTextField="Name" ListValueField="Value" /> 
                            <telerik:GridCheckBoxColumn DataField="Fisicos" HeaderText="Fisicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Biologicos" HeaderText="Biologicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Hidrologicos" HeaderText="Hidrologicos" /> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <DataBinding Location="WsDatosAO.svc" FilterParameterType="Linq" SelectMethod="GetEstacionesDataAndCount" 
                            SortParameterType="Linq">  
                        </DataBinding> 
                        <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnDataBound="RadGrid1_DataBound" /> 
                        <Selecting AllowRowSelect="true" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 
                <asp:ObjectDataSource ID="odsTipoEstacion" runat="server" SelectMethod="GetDomain" 
                    TypeName="Muestreos.WsDatosAO">  
                    <SelectParameters> 
                        <asp:Parameter DefaultValue="Muestreo" Name="DomainName" Type="String" /> 
                    </SelectParameters> 
                </asp:ObjectDataSource> 

 

0
Veli
Telerik team
answered on 12 Aug 2009, 01:29 PM
Hi Roberto,

This is exactly the correct approach to take. Probably, your GridDropDownColumn is not properly configured. Here is an article you can refer to:

Customize/Configure GridDropDownColumn

Sincerely yours,
Veli
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
Roberto
Top achievements
Rank 2
answered on 12 Aug 2009, 07:10 PM
If i set my grid datasource from the datasourceid tag

 <telerik:RadGrid ID="RadGrid2" runat="server" Skin="Black" AllowPaging="True"   
            DataSourceID="ObjectDataSource1" GridLines="None">  
                    <MasterTableView ClientDataKeyNames="Identificador">  
                        <PagerStyle Mode="NextPrev" /> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="Identificador" HeaderText="Identificador"   
                                Display="False" UniqueName="Identificador" /> 
                            <telerik:GridBoundColumn DataField="Proyecto" HeaderText="Proyecto" Display="false" /> 
                            <telerik:GridBoundColumn DataField="Nombre" HeaderText="Estación" /> 
                             <telerik:GridDropDownColumn DataField="Tipo" HeaderText="Tipo de Estación" DataSourceID="odsTipoEstacion" 
                                ListTextField="Name" ListValueField="Value" DataType="System.String" DropDownControlType="RadComboBox" 
                                 ForceExtractValue="Always" /> 
                            <telerik:GridCheckBoxColumn DataField="Fisicos" HeaderText="Fisicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Biologicos" HeaderText="Biologicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Hidrologicos" HeaderText="Hidrologicos" /> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnDataBound="RadGrid1_DataBound" /> 
                        <Selecting AllowRowSelect="true" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 

and not from Client DataBinding

<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Black" AllowPaging="true" PageSize="10">  
                    <MasterTableView ClientDataKeyNames="Identificador">  
                        <PagerStyle Mode="NextPrev" /> 
                        <Columns> 
                            <telerik:GridBoundColumn DataField="Identificador" HeaderText="Identificador" Display="false" /> 
                            <telerik:GridBoundColumn DataField="Proyecto" HeaderText="Proyecto" Display="false" /> 
                            <telerik:GridBoundColumn DataField="Nombre" HeaderText="Estación" /> 
                             <telerik:GridDropDownColumn DataField="Tipo" HeaderText="Tipo de Estación" DataSourceID="odsTipoEstacion" 
                                ListTextField="Name" ListValueField="Value" DataType="System.String" DropDownControlType="RadComboBox" 
                                 ForceExtractValue="Always" /> 
                            <telerik:GridCheckBoxColumn DataField="Fisicos" HeaderText="Fisicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Biologicos" HeaderText="Biologicos" /> 
                            <telerik:GridCheckBoxColumn DataField="Hidrologicos" HeaderText="Hidrologicos" /> 
                        </Columns> 
                    </MasterTableView> 
                    <ClientSettings> 
                        <DataBinding Location="WsDatosAO.svc" FilterParameterType="Linq" SelectMethod="GetEstacionesDataAndCount" 
                            SortParameterType="Linq">  
                        </DataBinding> 
                        <ClientEvents OnRowSelected="RadGrid1_RowSelected" OnDataBound="RadGrid1_DataBound" /> 
                        <Selecting AllowRowSelect="true" /> 
                    </ClientSettings> 
                </telerik:RadGrid> 

Everything works fine but i need to pass parameters to the grid datasource from the client side api and im not sure if setting the datasource in this way it could be possible.

Any way, i think there is a bug when the source of the grid is set by the databinding tag.
0
Veli
Telerik team
answered on 13 Aug 2009, 10:04 AM
Hello Roberto,

RadGrid's GridDropDownColumn does not support client-side binding to web services. If you bind RadGrid on the client, you need to implement your custom mechanism for populating a GridDropDownColumn or a similarly-functioning template column.

You can find a small web site I have created for your reference. Inside, I have a RadGrid with client-side data binding to page methods. Additionally, I use client-side logic to manually fetch data for my GridDropDownColumn and set the values in the cells.

Best wishes,
Veli
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
Veli
Telerik team
answered on 13 Aug 2009, 10:06 AM
Hi Roberto,

Please, excuse me, here is the actual attachment.

Regards,
Veli
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
SUNIL
Top achievements
Rank 2
Iron
answered on 13 Sep 2012, 08:44 PM
Hi Roberto,

You can also use a simple approach, which I used when using a web service to get the data for a Grid Dropdown column.
Use an ObjectDataSource in your page, and set the DataSourceID for Grid Dropdown column to the id of this ObjectDataSource.
Then, make sure that you specify a select method for object data source and call your web service method from inside the select method. I have provided some sample code below that I used. Follow the 3 steps below and you are all set to go.

  • Define ObjectDataSource in your page.  The'typename' for object datasource is simply the type of your page with the full namespace, which you can get from the 'Inherits' attribute from your 'Page' tag at the top of your page's html.
<%@ Page Title="" Language="C#" MasterPageFile="~/Generic.Master" AutoEventWireup="true" CodeBehind="BaseTierAlertSettings.aspx.cs" Inherits="ABC.Web.WebClient.BaseTierAlertSettings" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<asp:ObjectDataSource ID="CommandTypes" runat="server"
     SelectMethod="GetCommandTypes" TypeName="ABC.Web.WebClient.BaseTierAlertSettings"></asp:ObjectDataSource>

  • Define the select method in  your code behind, from which you call your web service and return a generic collection of custom objects. Make sure that you define the custom objects in your page's code behind. In my case, I defined the custom object 'BaseTierManagerCommandTypeLocal' within the page's code-behind.
public List<BaseTierManagerCommandTypeLocal> GetCommandTypes()
 {
     List<BaseTierManagerCommandTypeLocal> cts = new List<BaseTierManagerCommandTypeLocal>();
 
     ServiceClient dsc = new ServiceClient();
 
     try
     {
 
         CommandTypes = dsc.GetBaseTierManagerCommandTypes();
         BaseTierManagerCommandTypeLocal ct = null;
          
         foreach (BaseTierManagerCommandType commandType in CommandTypes)
         {
             ct = new BaseTierManagerCommandTypeLocal();
             ct.CommandTypeID = commandType.CommandTypeID;
             ct.CommandTypeName = commandType.CommandTypeName;
             ct.CommandTypeDescription = commandType.CommandTypeDescription;
             cts.Add(ct);
         }
 
     }
     catch (Exception ex)
     {
         if (dsc.State == System.ServiceModel.CommunicationState.Faulted)
         {
             dsc.Abort();
         }
 
         throw ex;
     }
     finally
     {
         dsc.Close();
     }
     return cts;

  • The    'BaseTierManagerCommandTypeLocal' is also defined in the page code-behind. The web service in my case was returning ''BaseTierManagerCommandType' and so you need to convert the web service object to your local object in your select method for objectdatasource . Make sure you define an empty parameterless constructor for this local object type.

public class BaseTierManagerCommandTypeLocal
  {
      
      public int CommandTypeID { get; set; }
       
      public string CommandTypeName { get; set; }
       
      public string CommandTypeDescription { get; set; }
      
      public string Tag { get; set; }
      //Store any custom data you would like in the Tag property, which you cannot fulfill by using existing data types.
 
      public BaseTierManagerCommandTypeLocal()
      {
      }
 
  }

Tags
Grid
Asked by
Roberto
Top achievements
Rank 2
Answers by
Veli
Telerik team
Roberto
Top achievements
Rank 2
SUNIL
Top achievements
Rank 2
Iron
Share this question
or