So I found this example on how create a dropdown and bind it to the grid.
<!--GridDropDownColumn example--> |
<telerik:GridDropDownColumn DataSourceID="SqlDataSource3" ListTextField="City" ListValueField="City" |
UniqueName="City" HeaderText="RadComboBox Column" DataField="City" |
DropDownControlType="RadComboBox"> |
</telerik:GridDropDownColumn> |
<!--New SqlDataSource for DropDownColumn --> |
<asp:SqlDataSource runat="server" ID="SqlDataSource3" ConnectionString="<%$ |
ConnectionStrings:NorthwindConnectionString %>" |
SelectCommand="SELECT DISTINCT [City] FROM [Employees]"> |
</asp:SqlDataSource> |
But lets say I have 3 columns: Col1, Col2 and Col3
Col1 is a drop down with static values.
Col2 is a dropdown as well but the values displayed will be dependent on what value was selected in Col1.
Col3 is a dropdown as well but the values displayed will be dependent on what values were select in Col1 and Col2.
I would need to use a stored procedure for this, no in-line sql code can be used.
Would you be able to show me an example of how to do this?
Thanks,
Nathan
ps. if you could do vb examples if possilbe
12 Answers, 1 is accepted
0

Princy
Top achievements
Rank 2
answered on 05 Feb 2010, 07:48 AM
Hi Nathan,
You can access the dropdownlist for the first DropDownColumn in the ItemCreated event and attach a SelectedIndexChanged event handler to it. Then in the SelectedIndexChanged event you can acess the dropdownlist for the second DropDownColumn and populate it . based on the selected text of the first dropdownlist. Follow the similar approach for the third DropDownColumn as well. Here is an online demo whihc you could refer to which demonstrtaes a similar functionality
Accessing cells and rows
Hope this helps..
Princy.
You can access the dropdownlist for the first DropDownColumn in the ItemCreated event and attach a SelectedIndexChanged event handler to it. Then in the SelectedIndexChanged event you can acess the dropdownlist for the second DropDownColumn and populate it . based on the selected text of the first dropdownlist. Follow the similar approach for the third DropDownColumn as well. Here is an online demo whihc you could refer to which demonstrtaes a similar functionality
Accessing cells and rows
Hope this helps..
Princy.
0

Nathan
Top achievements
Rank 1
answered on 05 Feb 2010, 03:36 PM
Ok, having trouble properly populating by dropdown first: (Col1 )
I am trying to go off this example:
http://www.telerik.com/help/aspnet-ajax/grdcustomizeconfiguregriddropdowncolumn.html
I cannot figure out how to tie my data from my database to the ListDataMemember.
ListDataMemeber is StatusSelect as shown below:
So I have returned my data from the database into a dataTable called dsStatus in the Page_Load procedure.
Now how do I tie the ListDataMemeber like in the example? In this example, the ListDataMemeber is "AccessLevel".
BTW, I want to try to go away from SQLDataSource controls so I can keep all my stored procedure calls in one file. Doing as described in my first post would prevent this.
I am trying to go off this example:
http://www.telerik.com/help/aspnet-ajax/grdcustomizeconfiguregriddropdowncolumn.html
I cannot figure out how to tie my data from my database to the ListDataMemember.
ListDataMemeber is StatusSelect as shown below:
<telerik:GridDropDownColumn DataField="StatusID" |
ListDataMember="StatusSelect" HeaderText="Account Status" |
ListTextField="Status" ListValueField="StatusID" ReadOnly="True" |
UniqueName="AccountStatusID2"> |
</telerik:GridDropDownColumn> |
So I have returned my data from the database into a dataTable called dsStatus in the Page_Load procedure.
Dim DataInformation As New DataController |
Dim dsStatus As DataTable = DataInformation.GetAccountStatus() |
Now how do I tie the ListDataMemeber like in the example? In this example, the ListDataMemeber is "AccessLevel".
'sample select command for GridDropDownColumn data-source generation |
DBadapter.SelectCommand = New OleDbCommand("SELECT DDL_AccessLevelID, Description FROM AccessLevel", conn) |
DBadapter.Fill(MyUsersData, "AccessLevel") |
BTW, I want to try to go away from SQLDataSource controls so I can keep all my stored procedure calls in one file. Doing as described in my first post would prevent this.
0

Nathan
Top achievements
Rank 1
answered on 17 Feb 2010, 06:32 PM
bump
0

Nathan
Top achievements
Rank 1
answered on 17 Feb 2010, 09:54 PM
Princy,
The RadGrid1_ItemDataBound isn't getting called. Shouldn't this get called when in edit mode?
Procedure wrong.
The RadGrid1_ItemDataBound isn't getting called. Shouldn't this get called when in edit mode?
Procedure wrong.
0

Erwin Floresca
Top achievements
Rank 1
answered on 17 Feb 2010, 11:59 PM
If you are not using sqldatas ource or object datasource you can bind the dropdown in the ItemCreated Event. These dropdowns will be available only in edit mode though. Following sample code might be helpful.
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated |
If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
'the combobox will be the first control in the Controls collection of the corresponding cell |
Dim list As RadComboBox = CType(CType(e.Item, GridEditableItem)("ddlOrderID").Controls(0), RadComboBox) |
Dim DataInformation As New DataController |
Dim dsStatus As DataTable = DataInformation.GetAccountStatus() |
list.DataSource = dsStatus |
list.DataTextField = "DescriptionColumn" |
list.DataValueField = "CodeColumn" |
list.DataBind() |
'attach SelectedIndexChanged event for the combobox control |
list.AutoPostBack = True |
AddHandler list.SelectedIndexChanged, AddressOf Me.list_SelectedIndexChanged |
End If |
End Sub |
0

Nathan
Top achievements
Rank 1
answered on 18 Feb 2010, 01:53 PM
I am getting closer...
The issue is when the grid loads, all rows (AccountStatus) are blank.
And how do I get the description instead of the ID to be displayed in the grid (not the dropdown) when not in edit mode?
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Template Status"> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlStatus" DataField="AccountStatusID" runat="server" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then |
Dim dsAccountStatus As DataTable = AccountStatus() |
Dim editform As GridEditFormItem = DirectCast(e.Item, GridEditFormItem) |
Dim ddl As DropDownList = DirectCast(editform.FindControl("ddlStatus"), DropDownList) |
ddl.DataSource = dsAccountStatus |
ddl.DataTextField = "StatusDescription" |
ddl.DataValueField = "StatusID" |
ddl.DataBind() |
End If |
The issue is when the grid loads, all rows (AccountStatus) are blank.
And how do I get the description instead of the ID to be displayed in the grid (not the dropdown) when not in edit mode?
0

Nathan
Top achievements
Rank 1
answered on 18 Feb 2010, 05:38 PM
Anyone? I could really use some help on this.
0

Erwin Floresca
Top achievements
Rank 1
answered on 18 Feb 2010, 07:14 PM
you will specify a label in the itemtemplate to display the description when not in edit mode
Make sure that you have "AccountStatusDesc" as a column in your dataset.
To display the description in the dropdown you need to specify DataTextField property for the dropdown.
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Template Status"> <ItemTemplate> <asp:Label id="lblStatusDesc" runat="server" Text='<%= DataBinder.Eval(Container.DataItem, " AccountStatusDesc") %>'> </ItemTemplate> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlStatus" DataField="AccountStatusID" runat="server" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
Make sure that you have "AccountStatusDesc" as a column in your dataset.
To display the description in the dropdown you need to specify DataTextField property for the dropdown.
0

Nathan
Top achievements
Rank 1
answered on 18 Feb 2010, 08:28 PM
I cannot believe I am still not getting this.
So I added AccountStatusDescription to my dataset like you said so the lblSTatuDesc should get access to it throught the NeedeDataSource?
Then added the Label to my template.
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Template Status"> |
<ItemTemplate> |
<asp:Label id="lblStatusDesc" runat="server" Text='<%= DataBinder.Eval(Container.DataItem, "AccountStatusDescription") %>' /> |
</ItemTemplate> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlStatus" DataField="AccountStatusID" runat="server" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
But when my grid loads all of the Status Rows are blank still. When I click edit I see my dropdown with the correct values but the correct value isn't selected. I am guessing this is because the field is blank.
How does the Label get the AccountStatusDescription from the DataBinder.Eval(Constainer.DataItem)? I am loading the contents into my grid programatically withing the NeedDataSource.
0

Erwin Floresca
Top achievements
Rank 1
answered on 18 Feb 2010, 08:51 PM
when you run the stored procedure what are the values you see in the AccountStatusDesc? It looks like the data is returned as blank.
0

Nathan
Top achievements
Rank 1
answered on 18 Feb 2010, 08:55 PM
No, they are not blank when I run the stored procedure here are the return results (minus all the other return columns and data)
AccountStatusID AccountStatusDescription
3 Both
2 Open
2 Open
Please note I have two stored procedures (you may have gotten that) 1 to populate the main grid (which I have added the description to) and 1 to populate the dropdown.
0

Erwin Floresca
Top achievements
Rank 1
answered on 19 Feb 2010, 04:08 AM
I just realized that the syntax I gave for binding the lblStatusDesc is not right. It should be
http://weblogs.asp.net/rajbk/archive/2004/07/20/what-s-the-deal-with-databinder-eval-and-container-dataitem.aspx
Please try it and see if it works.
<telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Template Status"> |
<ItemTemplate> |
<asp:Label id="lblStatusDesc" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "AccountStatusDescription") %>' /> |
</ItemTemplate> |
<EditItemTemplate> |
<asp:DropDownList ID="ddlStatus" DataField="AccountStatusID" runat="server" /> |
</EditItemTemplate> |
</telerik:GridTemplateColumn> |
http://weblogs.asp.net/rajbk/archive/2004/07/20/what-s-the-deal-with-databinder-eval-and-container-dataitem.aspx
Please try it and see if it works.