Add custom data to dataitem similar to adding attributes in ItemDataBound event

Thread is closed for posting
1 posts, 0 answers
  1. Peter
    Peter avatar
    12 posts
    Member since:
    Jan 2017

    Posted 23 Jan 2019 Link to this post


    Telerik Product and Version

    UI for ASP.NET AJAX 2019 R1

    Supported Browsers and Platforms

    all browsers supported by Telerik UI for ASP.NET AJAX suite

    Components/Widgets used (JS frameworks, etc.)

    RadMultiColumnComboBox, .NET 4.0/4.5 C#


    This project shows how to modify the data items from SqlDataSource to add or hide any information to an item. This is similar to using and ItemDataBound server-side event and add some attributes to the item.

    <telerik:RadMultiColumnComboBox runat="server" ID="RadMultiColumnComboBox1" Skin="Default"
        Height="400px" Width="300px"
        DataTextField="Name" DataValueField="ID"
        Placeholder="select from the dropdown or type">
            <telerik:MultiColumnComboBoxColumn Field="Description" Title="Name" Width="450px" />
            <telerik:MultiColumnComboBoxColumn Field="Title" Title="Title" Width="200px" />
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
        SelectCommand="SELECT Top 20 [CustomerID], [ContactName], [ContactTitle], [CompanyName] FROM [Customers]"></asp:SqlDataSource>

    protected void Page_Load(object sender, EventArgs e)
        DataSourceSelectArguments args = new DataSourceSelectArguments();
        DataView view = (DataView) SqlDataSource1.Select(args);
        DataTable dt = view.ToTable();
        RadMultiColumnComboBox1.DataSource = GetModifiedDataSource(dt);
    private DataTable GetModifiedDataSource(DataTable dt)
        DataTable dataTable = new DataTable();
        dataTable.Columns.Add(new DataColumn("ID", typeof(string)));
        dataTable.Columns.Add(new DataColumn("Name", typeof(string)));
        dataTable.Columns.Add(new DataColumn("Description", typeof(string)));
        dataTable.Columns.Add(new DataColumn("Title", typeof(string)));
        dataTable.PrimaryKey = new DataColumn[] { dataTable.Columns["ID"] };
        var rowsCount = dt.Rows.Count;
        for (int i = 0; i < rowsCount; i++)
            DataRow dataRow = dt.Rows[i];
            DataRow row = dataTable.NewRow();
            row["ID"] = dataRow["CustomerID"];
            row["Name"] = dataRow["ContactName"];
            row["Description"] = dataRow["ContactName"] + " from " + dataRow["CompanyName"];
            row["Title"] = dataRow["ContactTitle"];
        return dataTable;

Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.