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

Custom DropDownListColumn in edit

11 Answers 141 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 08 Feb 2012, 05:53 PM
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

11 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Feb 2012, 06:42 AM
Hello,

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

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 09 Feb 2012, 02:19 PM
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
0
Jocelyn
Top achievements
Rank 1
answered on 13 Feb 2012, 08:53 PM
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
0
Veli
Telerik team
answered on 14 Feb 2012, 01:25 PM
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 >>
0
Jocelyn
Top achievements
Rank 1
answered on 14 Feb 2012, 03:12 PM
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?
0
Jocelyn
Top achievements
Rank 1
answered on 14 Feb 2012, 03:36 PM
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?
0
Accepted
Veli
Telerik team
answered on 14 Feb 2012, 03:44 PM
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 >>
0
Jocelyn
Top achievements
Rank 1
answered on 14 Feb 2012, 03:59 PM
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
0
Accepted
Veli
Telerik team
answered on 14 Feb 2012, 04:08 PM
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 >>
0
Jocelyn
Top achievements
Rank 1
answered on 14 Feb 2012, 04:23 PM
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
0
Jocelyn
Top achievements
Rank 1
answered on 14 Feb 2012, 05:05 PM
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!
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Veli
Telerik team
Share this question
or