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

Populate RAD Combo inside Rad Grid

1 Answer 131 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 09 Jun 2014, 11:33 AM
Hi,

I am new to telerik, I want to design page having a grid which should allow user to insert new row & allow batch update to modify exsisting items, grid should also have combo box columns. I want to poplate grid and all combo box kept in Edit item template on code behind.
please let me know how to do this.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Jun 2014, 08:20 AM
Hi Rahul,

Please try to bind the RadGrid in OnNeedDataSource event and RadComboBox in OnPreRender event as follows.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnPreRender="RadGrid1_PreRender">
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
        <BatchEditingSettings EditType="Row" />
        <Columns>
            <telerik:GridTemplateColumn DataField="OrderID" UniqueName="OrderID">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" runat="server" EmptyMessage="select">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    RadGrid1.DataSource = GetDataTable("SELECT [OrderID],[CustomerID] FROM Orders");
}
public DataTable GetDataTable(string query)
{
    String ConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(ConnString);
    SqlDataAdapter adapter = new SqlDataAdapter();
    adapter.SelectCommand = new SqlCommand(query, conn);
    DataTable myDataTable = new DataTable();
    conn.Open();
    try
    {
        adapter.Fill(myDataTable);
    }
    finally
    {
        conn.Close();
    }
    return myDataTable;
}
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadComboBox combo = RadGrid1.FindControl(RadGrid1.MasterTableView.ClientID + "_OrderID").FindControl("RadComboBox1") as RadComboBox;
    combo.DataSource = GetDataTable("SELECT [OrderID] FROM Orders");
    combo.DataTextField = "OrderID";
    combo.DataBind();
}

Let me know if you have any concern.
Thanks,
Princy.
Tags
ComboBox
Asked by
Rahul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or