First time using RadComboBox

4 posts, 0 answers
  1. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 11 Dec 2012 Link to this post

    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

  2. Kevin
    Kevin avatar
    360 posts
    Member since:
    Jul 2012

    Posted 12 Dec 2012 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 12 Dec 2012 Link to this post

    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
  5. Robert
    Robert avatar
    253 posts
    Member since:
    Aug 2007

    Posted 12 Dec 2012 Link to this post

    Kevin,

    I finally got things working!

    Thank you again for your help,

    Robert
Back to Top