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

First time using RadComboBox

3 Answers 56 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 12 Dec 2012, 05:13 AM
Throughout my ASP.Net app I've successfully used the standard DropDownListBox control.  However, I now have a special circumstance in which I need to multiple columns of information rather than the standard single column.  So I'm using the RadComboBox for the first time.  However, reading through the documentation I'm somewhat confused about how to correctly populate it.

Here's my scenario:

I have a DataTable with 3 fields:
  1. Master_Idx
  2. Description
  3. LevelIdx

In the RadComboBox I wish to display two columns:

  1. Description
  2. A special calculated field which stems from LevelIdx

So in the layout page I've defined the RadComboBox like this:

<telerik:RadComboBox ID="radListBox" runat="server" OnSelectedIndexChanged="radListBox_SelectedIndexChanged">
   <ItemTemplate>
      <table>
         <tr>
            <td><%# DataBinder.Eval(Container.DataItem, "Description") %></td>
            <td><%# GetPass_ContractLevel(Convert.ToInt32(Container.DataItem, "LevelIdx"))) %></td>
         </tr>
      </table>
   </ItemTemplate>                        
</telerik:RadComboBox>

In my server-side code I'm populating the RadComboBox like this:

            radList.DataSource = dataTable;
            radList.DataTextField = "Description";
            radList.DataValueField = "Master_Idx";
            radList.DataBind();

            for (int i = 0; i < radList.Items.Count; i++)
            {
              radList.Items[i].DataBind();
            }

The problem is that the LevelIdx value being passed to the server-side method "GetPass_ContractLevel" is always zero.  However, I've successfully implemented "helper" methods like this before which are called from the layout code.  It doesn't seem to be working in this case though.

What am I doing wrong?

Robert

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 12 Dec 2012, 09:18 PM
Hello Robert,

This line:

<td><%# GetPass_ContractLevel(Convert.ToInt32(Container.DataItem, "LevelIdx"))) %></td>

should be written like this:

<td><%# GetPass_ContractLevel(Convert.ToInt32(Eval("LevelIdx"))) %></td>

Also, you don't need to loop through each RadComboBoxItem and call DataBind, as the RadComboBox.DataBind call is enough.

I hope that helps.
0
Robert
Top achievements
Rank 1
answered on 12 Dec 2012, 10:28 PM
Kevin,

Thank you for your response.  In an earlier version of my work, I thought I had exactly what you were suggesting but I suppose my syntax wasn't quite right.  In any case, I copied & pasted your sample layout code and now it no longer crashes.

However, I still do have the problem that it's not showing the 2nd column, only the first one.  Here's my current code:

<telerik:RadComboBox ID="radListBox" runat="server" OnSelectedIndexChanged="radListBox"_SelectedIndexChanged" Width="170" AllowCustomText="false" HighlightTemplatedItems="true">
  <HeaderTemplate>
    <ul>
      <li class="radListColumn">Description</li>
      <li class="radListColumn">Contract/Level</li>
    </ul>
  </HeaderTemplate>
  <ItemTemplate>
    <ul>
      <li class="radListColumn">
        <%# DataBinder.Eval(Container.DataItem, "Description") %>
      </li>
      <li class="radListColumn">
        <%# GetPass_ContractLevel(Convert.ToInt32(Eval("LevelIdx"))) %>
      </li>
    </ul>
  </ItemTemplate>
</telerik:RadComboBox>

radListBox.DataSource = CurrentPasses;
radListBox.DataTextField = "Description";
radListBox.DataValueField = "Master_Idx";
radListBox.DataBind();

/************************
  Used by the RadComboBox
*************************/
 
.radListColumn {
    margin: 0;
    padding: 0 5px 0 0;
    width: 50px;
    line-height: 14px;
    float: left;
}
 
/** End of RadComboBox styles **/

What am I doing wrong such that the multiple columns aren't displayed?

Robert
0
Robert
Top achievements
Rank 1
answered on 13 Dec 2012, 05:06 AM
Kevin,

I finally got things working!

Thank you again for your help,

Robert
Tags
ComboBox
Asked by
Robert
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Robert
Top achievements
Rank 1
Share this question
or