Computer Surgeon
Top achievements
Rank 1
Computer Surgeon
asked on 21 Dec 2008, 10:45 AM
Hi,
I need to populate text , value pair in RadComboBox. Please help me out to get ride of filling datasource in radcombobox which is placed within radgirid Edit Item Template. Without using DataSourceID="SqlDataSource1" . And binding radcombobox using codebehind on RadGrid Item databound.
While i click on "ADD NEW RECORD " the RadComboBox within the EditItemTemplate sholud get populated.
I need to populate text , value pair in RadComboBox. Please help me out to get ride of filling datasource in radcombobox which is placed within radgirid Edit Item Template. Without using DataSourceID="SqlDataSource1" . And binding radcombobox using codebehind on RadGrid Item databound.
While i click on "ADD NEW RECORD " the RadComboBox within the EditItemTemplate sholud get populated.
<
telerik:GridTemplateColumn HeaderText="Document Type" HeaderButtonType="TextButton">
<ItemTemplate>
<asp:Label runat="server" ID="lblDocType" Text='<%# Eval("DocumentType") %>' />
</ItemTemplate>
<EditItemTemplate>
<telerik:RadComboBox ID="RCBAccDocType" runat="server" Width="130px" Skin="Office2007">
</telerik:RadComboBox>
</EditItemTemplate>
<ItemStyle Width="12%" HorizontalAlign="Left" />
<HeaderStyle Width="12%" HorizontalAlign="Center" />
</telerik:GridTemplateColumn>
Thanks!,
Happy coding ;-)
5 Answers, 1 is accepted
0
Accepted
Shinu
Top achievements
Rank 2
answered on 22 Dec 2008, 05:54 AM
HI,
Try the following code snippet to fill the DropDownList in Insert mode.
ASPX:
CS:
Thanks
Shinu
Try the following code snippet to fill the DropDownList in Insert mode.
ASPX:
<telerik:GridTemplateColumn HeaderText="TempCol" UniqueName="TempCol" > |
<EditItemTemplate> |
<asp:DropDownList ID="RCBAccDocType" runat="server"> |
</asp:DropDownList> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if ((e.Item is GridEditFormInsertItem) && (e.Item.OwnerTableView.IsItemInserted)) |
{ |
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item; |
DropDownList combo = (DropDownList)insertItem["TempCol"].FindControl("RCBAccDocType"); |
SqlConnection conn = new SqlConnection(connectionstring); |
conn.Open(); |
SqlDataAdapter adp = new SqlDataAdapter("select ProductName,ProductID from Products ", conn); |
DataTable dt = new DataTable(); |
adp.Fill(dt); |
combo.DataSource = dt; |
combo.DataTextField = "ProductName"; |
combo.DataValueField = "ProductID"; |
combo.DataBind(); |
conn.Close(); |
} |
} |
Thanks
Shinu
0
Computer Surgeon
Top achievements
Rank 1
answered on 22 Dec 2008, 06:24 AM
Thanks for your guidance.
0
Atit Thaker
Top achievements
Rank 1
answered on 15 Oct 2009, 11:15 AM
Hi,
Thanx for you help buddy. :)
I am attaching your code in vb.net :
If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then
Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
Dim combo As DropDownList = DirectCast(insertItem("Roles").FindControl("RCBAccDocType"), DropDownList)
combo.DataSource = dsh.PersonnelRole
combo.DataTextField = "RoleName"
combo.DataValueField = "PersonnelRoleID"
combo.DataBind()
End If
Thanx for you help buddy. :)
I am attaching your code in vb.net :
If (TypeOf e.Item Is GridEditFormInsertItem) AndAlso (e.Item.OwnerTableView.IsItemInserted) Then
Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem)
Dim combo As DropDownList = DirectCast(insertItem("Roles").FindControl("RCBAccDocType"), DropDownList)
combo.DataSource = dsh.PersonnelRole
combo.DataTextField = "RoleName"
combo.DataValueField = "PersonnelRoleID"
combo.DataBind()
End If
0
Maulin
Top achievements
Rank 1
answered on 12 May 2016, 11:16 AM
Is there a way to do same thing on clientside ?
0
Hi Maulin,
I am afraid you cannot bind the RadComboBox on the client since grid requires the selected value to be send to the server. Nevertheless, a possible solution is to use load on demand feature of the ComboBox control to populate it. Please check out the following live example which demonstrates that.
Regards,
Kostadin
Telerik
I am afraid you cannot bind the RadComboBox on the client since grid requires the selected value to be send to the server. Nevertheless, a possible solution is to use load on demand feature of the ComboBox control to populate it. Please check out the following live example which demonstrates that.
Regards,
Kostadin
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.