3 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Oct 2013, 01:15 PM
Hi Dawson,
Please try the following code snippet to bind the RadComboBox from code behind in editmode.
ASPX:
C#:
Thanks,
Princy
Please try the following code snippet to bind the RadComboBox from code behind in editmode.
ASPX:
<
telerik:GridTemplateColumn
HeaderText
=
"ShipCountry"
DataField
=
"ShipCountry"
>
<
ItemTemplate
>
<%# Eval("ShipCountry")%>
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadComboBox
ID
=
"RadCombobox1"
runat
=
"server"
>
</
telerik:RadComboBox
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:Northwind_newConnectionString3 %>" SelectCommand="SELECT distinct [ShipCountry] FROM [Orders]"></
asp:SqlDataSource
>
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem edit = (GridEditableItem)e.Item;
RadComboBox combo = (RadComboBox)edit.FindControl(
"RadCombobox1"
);
combo.DataSourceID =
"SqlDataSource2"
;
combo.DataTextField =
"ShipCountry"
;
combo.DataValueField =
"ShipCountry"
;
}
}
Thanks,
Princy
0
Dawson
Top achievements
Rank 1
answered on 11 Oct 2013, 07:38 AM
Hi Princy,
Thanks for your code.. It works fine. .
But I want it to set to the default value it holds.right now its showing the values from start.how to make it select the value it holds for that row.
Thanks again,
Dawson.
0
Accepted
Princy
Top achievements
Rank 2
answered on 11 Oct 2013, 07:46 AM
Hi Dawson,
Please add the following code to the ItemDataBound event to get the selected value to be the current value.
C#:
Thanks,
Princy
Please add the following code to the ItemDataBound event to get the selected value to be the current value.
C#:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditableItem && e.Item.IsInEditMode)
{
//Same code as above
combo.SelectedValue = DataBinder.Eval(edit.DataItem,
"ShipCountry"
).ToString();
}
}
Thanks,
Princy