I am new in using Telerik radcontrol in asp.net.
i am trying to create a order form in this form using a gridview in this grid view have dropdownlist,label and two textbox.
first i bind to dropdown list that access data from sqldatabase.
i am unable to bind that
13 Answers, 1 is accepted

A better suggestion is to use 'GridDropDownColumn' where the following Demo describes how it works.
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/columntypes/defaultcs.aspx
If you want to customize that column, please go through the following documentation.
Customize/Configure GridDropDownColumn
You can also use DropDownList inside GridTemplateColumn.Then populate the control by setting its DataSourceID to SqlDataSource. Sample code is given below.
Mark-Up:
<
telerik:GridTemplateColumn
>
<
ItemTemplate
>
<
asp:DropDownList
DataTextField
=
"LastName"
DataValueField
=
"LastName"
runat
=
"server"
DataSourceID
=
"SqlDataSource1"
></
asp:DropDownList
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
Thanks,
Princy
I suggest that you examine the help topic below which discusses how to bind a dropdown control in EditItemTemplate:
Operations with MS DropDownList in EditItemTemplate of GridTemplateColumn
Kind regards,
Pavlina
the Telerik team

I have bind radgrid and try to bind dropdown but unable to do that my code is
<
telerik:RadGrid
ID
=
"radGrid1"
runat
=
"server"
AutoGenerateColumns
=
"False"
GridLines
=
"None"
AllowMultiRowEdit
=
"True"
OnItemDataBound
=
"radGrid1_DataBound"
OnNeedDataSource
=
"radGrid1_NeedDataSource"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Product Name"
>
<
EditItemTemplate
>
<
asp:DropDownList
ID
=
"ddl1"
runat
=
"server"
AutoPostBack
=
"true"
DataValueField
=
"Product_Id"
DataTextField
=
"Product_Name"
>
</
asp:DropDownList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Product_rate"
>
<
ItemTemplate
>
<
asp:Label
ID
=
"lblrate"
runat
=
"server"
Text='<%#DataBinder.Eval(Container.DataItem,"Product_Rate")%>'></
asp:Label
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Product Quantity"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"txtQuantity"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Product Amount"
>
<
ItemTemplate
>
<
asp:TextBox
ID
=
"txtAmount"
runat
=
"server"
/>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
protected void radGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlDataAdapter da = new SqlDataAdapter("select * from product_detail", connection);
DataTable dt = new DataTable();
connection.Open();
try
{
da.Fill(dt);
}
finally
{
connection.Close();
}
radGrid1.DataSource = dt.DefaultView;
}
protected void radGrid1_DataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
SqlConnection connection = new SqlConnection(ConfigurationManager.AppSettings["connectionstring"].ToString());
SqlDataAdapter da = new SqlDataAdapter("select product_id,product_name from product_detail", connection);
DataSet ds=new DataSet();
da.Fill(ds);
GridEditableItem item = e.Item as GridEditableItem;
DropDownList list = item.FindControl("ddl1") as DropDownList;
list.DataSource = ds;
list.DataTextField = "product_name";
list.DataValueField = "product_id";
list.DataBind();
}
}

But Incase i have retrieving data from sqldatabase then how can fill dropdownlist.
i do't want to use SqlDatSource ID.
plz suggest me.
thanks

I can't find any problem with your code. Could you check whether the DataSet is populating properly by puting breakpoint in the ItemDataBound event?
I hope someone from Telerik will help us.
Thanks,
Princy.

here my item data bound code is
protected void radGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
SqlConnection connection = new SqlConnection();
connection = new SqlConnection(ConfigurationManager.ConnectionStrings["chalk_hillConnectionString"].ConnectionString);
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand("select product_id,product_name from product_detail", connection);
DataSet ds = new DataSet();
try
{
da.Fill(ds, "product_detail");
}
finally
{
connection.Close();
}
radgrid1.DataSource = ds;
}
protected void radGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
DataRowView row = (DataRowView)e.Item.DataItem;
item["ddl1"].Text = row["product_name"].ToString();
}
}
<
telerik:RadGrid
ID
=
"radgrid1"
runat
=
"server"
OnNeedDataSource
=
"radGrid1_NeedDataSource"
OnItemDataBound
=
"radGrid1_ItemDataBound"
OnItemCreated
=
"radGrid1_ItemCreated"
AutoGenerateColumns
=
"false"
>
<
MasterTableView
AutoGenerateColumns
=
"false"
Width
=
"100%"
ShowHeader
=
"true"
>
<
Columns
>
<
telerik:GridDropDownColumn
UniqueName
=
"ddl1"
ListTextField
=
"Product_Name"
ListValueField
=
"Product_Id"
ListDataMember
=
"Product_Detail"
DataField
=
"Product_Id"
HeaderText
=
"Product_Name"
></
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
HeaderText
=
"Product_Rate"
UniqueName
=
" Product_Rate"
DataField
=
"Product_Rate"
></
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Please try using the following code and see if it helps to implement the desired functionality:
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, Telerik.Web.UI.GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item
as
GridEditableItem;
GridEditManager editMan = editedItem.EditManager;
GridDropDownListColumnEditor editor = (GridDropDownListColumnEditor)(editMan.GetColumnEditor(
"ddl1"
));
RadComboBox combo = editor.ComboBoxControl;
combo.AllowCustomText =
true
;
combo.MarkFirstMatch =
true
;
combo.DataSourse =
//set the desired data source
}
}
All the best,
Pavlina
the Telerik team


I have prepared a sample runnable page with grid and dropdownlist where AllowMultiRowEdit property is set to true and ItemDataBound event fires as expected. Please refer to the video below in order to see how it works on my end.
https://www.screencast.com/t/dFb7S7TCSd
Attached you can also find my test project. Please give it a try and let me know what is the difference on your end and if I missed something from your logic out.
I hope this helps.
Regards,
Pavlina
Progress Telerik

The link returns a 403 error and when I follow the zip file example, no data is being appended to the control.
Here is a sniplet:
<telerik:RadGrid ID="RadGrid1" runat="server" AllowMultiRowEdit="true" EnableViewState="false" AllowFilteringByColumn="True" AllowPaging="True" PageSize="20" AllowAutomaticDeletes="true" AllowAutomaticUpdates="true" AllowAutomaticInserts="true" AllowSorting="True" AutoGenerateDeleteColumn="True" AutoGenerateEditColumn="False" DataSourceID="SqlDataSource1" CellSpacing="0" GridLines="None" AutoGenerateColumns="false" Width="100%" style="margin:0px 10px 10px 10px" OnItemCreated="RadGrid1_ItemCreated" OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource">
<ClientSettings EnableRowHoverStyle="true" AllowColumnsReorder="True" AllowKeyboardNavigation="true">
<Selecting AllowRowSelect="True" />
</ClientSettings>
<MasterTableView EditMode="Batch" HorizontalAlign="NotSet" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" CommandItemDisplay="Bottom" DataKeyNames="EmployeeID" Width="100%">
<BatchEditingSettings EditType="Row" />
<CommandItemSettings ShowAddNewRecordButton="true" ShowExportToExcelButton="false" AddNewRecordText="Add new associate"/>
<Columns>
<telerik:GridTemplateColumn DataField="StatusCode" HeaderText="Status Code" SortExpression="StatusCode" UniqueName="StatusCode" HeaderStyle-Width="75px">
<FilterTemplate>
<telerik:RadComboBox ID="RCB_StatusCode" runat="server" Width="50px" SelectedValue='<%# ((GridItem)Container).OwnerTableView.GetColumn("StatusCode").CurrentFilterValue %>' OnClientSelectedIndexChanged="TitleIndexChanged">
<Items>
<telerik:RadComboBoxItem Value="" Text="All"/>
<telerik:RadComboBoxItem Value="A" Text="A" />
<telerik:RadComboBoxItem Value="L" Text="L" />
<telerik:RadComboBoxItem Value="P" Text="P" />
<telerik:RadComboBoxItem Value="T" Text="T" />
</Items>
</telerik:RadComboBox>
<telerik:RadScriptBlock ID="RadScriptBlock2" runat="server">
<script type="text/javascript">
function TitleIndexChanged(sender, args) {
var tableView = $find("<%# ((GridItem)Container).OwnerTableView.ClientID %>");
tableView.filter("StatusCode", args.get_item().get_value(), "EqualTo");
}
</script>
</telerik:RadScriptBlock>
</FilterTemplate>
<ItemTemplate>
<%# Eval("StatusCode") %>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RCB_StatusCode" runat="server" Width="50px" AppendDataBoundItems="true">
<Items>
<telerik:RadComboBoxItem Value="" Text="All"/>
</Items>
</telerik:RadComboBox>
<asp:RequiredFieldValidator ID="RFV_StatusCode" runat="server" ControlToValidate="RCB_StatusCode" Text="⇚" ForeColor="#E31932" Font-Bold="true" Font-Size="14pt" Display="Dynamic" SetFocusOnError="true" />
</EditItemTemplate>
</telerik:GridTemplateColumn>
</Columns>
</MasterTableView>
And the code behind:
private DataTable GetDataTable()
{
DataTable dataTable = new DataTable();
using (SqlConnection sqlConnection = new SqlConnection(SqlConn.WB()))
{
SqlCommand sqlCommand = new SqlCommand("select distinct StatusCode from dbo.MyScheduleUsers order by StatusCode", sqlConnection);
sqlCommand.CommandType = CommandType.Text;
SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
sqlDataAdapter.Fill(dataTable);
}
return dataTable;
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if(e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item as GridEditableItem;
RadComboBox RCB_StatusCode = item.FindControl("RCB_StatusCode") as RadComboBox;
RCB_StatusCode.DataSource = GetDataTable();
RCB_StatusCode.DataValueField = "StatusCode";
RCB_StatusCode.DataTextField = "StatusCode";
RCB_StatusCode.DataBind();
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
(sender as RadGrid).DataSource = GetDataTable();
}
So.... it's still not working....
Please find attached a sample project using your own code and combobox registration and a *.mp4 video demonstrating the whole scenario.
To be able to run the project on your end, you need to add the missing Telerik assemblies for .NET 4.5 in the bin folder.
Let me know if you have any questions.
Best regards,
Rumen
Progress Telerik
