Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Custom DropDownListColumn in edit

Answered Custom DropDownListColumn in edit

Feed from this thread
  • Jocelyn avatar

    Posted on Feb 8, 2012 (permalink)

    Hi,

    I am starting with Grid. I have a DropDownListColumn in Edit mode that I fill with a sql query in code. It show correctly the data that I want, but my data have 2 fields. One is a Number and the second is the Name corresponding to this number. I want to show these two fields in my DropDownList. Here is what I want:

    What I currently have and What I want

    Thanks

    Reply

  • Posted on Feb 9, 2012 (permalink)

    Hello,

    Take a look at the following help documentation.
    Customize/Configure GridDropDownColumn.

    Thanks,
    Princy.

    Reply

  • Jocelyn avatar

    Posted on Feb 9, 2012 (permalink)

    I read this Documentation before. But, what I am looking for is to be able to show more than one data per "row" in my ComboBox like my previous picture.

    A little example would be the best!

    Thanks

    Reply

  • Jocelyn avatar

    Posted on Feb 13, 2012 (permalink)

    How Can I have this:

      <telerik:RadComboBox ID="cboMedic" runat="server" Width="400px" Height="200px"
              MarkFirstMatch="True" EnableLoadOnDemand="True" DataTextField="medi_nom"
              DataValueField="medi_numero" HighlightTemplatedItems="True"  LoadingMessage="Chargement" ItemsPerRequest="10"
              ShowMoreResultsBox="true" EnableVirtualScrolling="true" OnItemsRequested="cboMedic_ItemsRequested">
            <ItemTemplate>
     
           <div class="cboContentContener">
              <span class="cboContent" style="display:block;font-weight:bold" >
                  <%#DataBinder.Eval(Container, "Attributes['medi_nom']")%></span>
              <span  class="cboContent">
                  <%#DataBinder.Eval(Container, "Attributes['medi_numero']")%></span>
                
                 -   
              <span class="cboContent">
                  <%#DataBinder.Eval(Container, "Attributes['meds_description']")%></span>
               
          </div>
      </ItemTemplate>
    </telerik:RadComboBox>

    In a GridDropDownListColumEditor? Can I do that directly in the aspx or I need to add it server side in the ItemDataBound event?

    What I need is te ItemTemplate in my DropDownListColumEditor.

    Thanks

    Reply

  • Veli Veli admin's avatar

    Posted on Feb 14, 2012 (permalink)

    Hello Jocelyn,

    Setting up the combo in your dropdown column properly depends on the databinding scenario you are using in RadGrid. Attached is a small test page demonstrating one approach you can use. Note that I am using databinding using DataSourceID and an ObjectDataSource control. If you are binding your grid another
    way the example might be different. Bottom line is, you need to create the combo template programmatically as demonstrated. We use the ItemCreated event in RadGrid to find the dropdown column editor for every edited item and initialize the ItemTemplate of the RadComboBox inside.

    I hope this helps.

    Veli
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • Jocelyn avatar

    Posted on Feb 14, 2012 (permalink)

    Thank you Veli,

    But I am working in VB. I am trying your example right now, but I don't know how to convert this in VB:

    idLabel.DataBinding += (sender, args) =>
        {
            Label label = (Label)sender;
            label.Text = DataBinder.Eval(((RadComboBoxItem)label.NamingContainer).DataItem, "ID").ToString();
        };

    Can you help me?

    Reply

  • Jocelyn avatar

    Posted on Feb 14, 2012 (permalink)

    And when I am trying this in the ItemCreated

    editGenerique.ComboBoxControl.ItemTemplate = New GeneriqueComboTemplate()

    The New is not calling the InstantiateIn in my private class inside my main class

    Private Class GeneriqueComboTemplate
        Implements ITemplate
     
        Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
            Dim panel As New Panel()
     
            panel.ID = "Container"
            panel.CssClass = "cboContentContener"
     
            Dim idLabel As New Label()
            idLabel.ID = "IDLabel"
            idLabel.CssClass = "cboContent"
     
            idLabel.Text = "allo"
            panel.Controls.Add(idLabel)
     
            Dim nameLabel As New Label()
            nameLabel.ID = "NameLabel"
            nameLabel.CssClass = "cboContent"
            nameLabel.Text = "NameAllo"
     
            panel.Controls.Add(nameLabel)
     
            container.Controls.Add(panel)
     
     
        End Sub
    End Class

    The code is just a test, but I can't get into the Sub... DId I miss something?

    Reply

  • Answer Veli Veli admin's avatar

    Posted on Feb 14, 2012 (permalink)

    Hello Jocelyn,

    Attached is the equivalent page in VB.NET.

    Veli
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
    Attached files

    Reply

  • Jocelyn avatar

    Posted on Feb 14, 2012 (permalink)

    Thank you Veli,

    Are you sure that the syntax is correct? Because I got compile error...

    AddHandler idLabel.DataBinding, Error 2
        Error3Sub(sender As Object, e As EventArgs)
            Dim thisLabel As Label = sender
            thisLabel.Text = DataBinder.Eval(DirectCast(thisLabel.NamingContainer, RadComboBoxItem).DataItem, "ID").ToString()
        End Sub

    Error 2 Expression expected.
    Error 3 Statement cannot appear within a method body. End of method assumed.
    - Jocelyn

    Reply

  • Answer Veli Veli admin's avatar

    Posted on Feb 14, 2012 (permalink)

    I am able to successfully build and run the page in a .NET 4.0 environment. Are  you using .NET 3.5? If so, the delegate subroutine simply needs to be refactored in an external subroutine.

    Veli
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>

    Reply

  • Jocelyn avatar

    Posted on Feb 14, 2012 (permalink)

    Yes I am using .NET Framework 3.5. Thank you for your help!!

    But do you have a clue why InstantiateIn is not called when I do 

    editGenerique.ComboBoxControl.ItemTemplate = New GeneriqueComboTemplate()

    Private Class GeneriqueComboTemplate
        Implements ITemplate
     
        Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
            Dim panel As New Panel()
     
            panel.ID = "Container"
            panel.CssClass = "cboContentContener"
     
            Dim idLabel As New Label()
            idLabel.ID = "IDLabel"
            idLabel.CssClass = "cboContent"
            AddHandler idLabel.DataBinding, AddressOf DataBindLabel1
     
     
            panel.Controls.Add(idLabel)
     
            Dim nameLabel As New Label()
            nameLabel.ID = "NameLabel"
            nameLabel.CssClass = "cboContent"
            AddHandler nameLabel.DataBinding, AddressOf DataBindLabel2
            panel.Controls.Add(nameLabel)
     
            container.Controls.Add(panel)
        End Sub
        Private Sub DataBindLabel1(ByVal sender As Object, ByVal e As EventArgs)
            Dim thisLabel As Label = sender
            thisLabel.Text = DataBinder.Eval(DirectCast(thisLabel.NamingContainer, RadComboBoxItem).DataItem, "gene_numero").ToString()
        End Sub
     
        Private Sub DataBindLabel2(ByVal sender As Object, ByVal e As EventArgs)
            Dim thisLabel As Label = sender
            thisLabel.Text = DataBinder.Eval(DirectCast(thisLabel.NamingContainer, RadComboBoxItem).DataItem, "gene_nom").ToString()
        End Sub
    End Class

    Thanks

    - Jocelyn

    Reply

  • Jocelyn avatar

    Posted on Feb 14, 2012 (permalink)

    I was using a DropDownList instead of a RadComboBox, so now I have my template, but I can't select any item, is that normal?

    Edit: Nervermind everything is working now.

    Thank you very much for you help!

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > Grid > Custom DropDownListColumn in edit
Related resources for "Custom DropDownListColumn in edit"

ASP.NET Grid Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]