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

RadGridView not using SqlDataSource

1 Answer 86 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Informatica - BES
Top achievements
Rank 1
Informatica - BES asked on 08 May 2014, 07:18 PM
Hi all,

I was looking for RadGridView sample's at telerik demo website and i did not found a demo the RadGridView don't use SqlDataSource to bind some data and some RadComboBox/RadDropDownList edit template columns.

Does anybody have an example of a radgridview that don't use SqlDataSources filled at code behind and have some RadComboBox/RadDropDownList edit template columns filled at code behind too?

Tks

1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 09 May 2014, 05:08 AM
Hi,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadGrid ID="radgrdOrders" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    AutoGenerateEditColumn="true" OnItemDataBound="radgrdOrders_ItemDataBound">
    <MasterTableView>
        <Columns>
            <telerik:GridTemplateColumn>
                <EditItemTemplate>
                    <telerik:RadComboBox ID="radcboOrderId" runat="server">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

C#:
DataTable data = new DataTable();
private static DataTable GetData(SqlCommand selectCommand)
{
    selectCommand.Connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
    SqlDataAdapter adapter = new SqlDataAdapter(selectCommand);
    DataTable tableData = new DataTable();
    adapter.Fill(tableData);
    return tableData;
}
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    data = GetData(new SqlCommand("SELECT Top 10 OrderID,CustomerID,EmployeeID FROM Orders"));
    radgrdOrders.DataSource = data;
}
protected void radgrdOrders_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem editableItem = (GridEditableItem)e.Item;
        RadComboBox comboBox =(RadComboBox) editableItem.FindControl("radcboOrderId");
        data = GetData(new SqlCommand("SELECT Top 10 OrderID,CustomerID FROM Orders"));
        comboBox.DataSource = data;
        comboBox.DataTextField = "CustomerID";
        comboBox.DataValueField = "OrderID";
        comboBox.DataBind();
    }
}

Thanks,
Shinu.
Tags
Grid
Asked by
Informatica - BES
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or