Bind radComboBox within a radGrid's automatic Edit Form?

I have been trying to figure out how to bind sql data to a radCombo box that is nested within a radGrid's automatic Edit Form.
Oddly enough, I was able to figure out how to "cascade" the radCombo boxes Department & ActivityNum as shown in the screenshot.  What I have not figured out is how to initially bind ActivityNum onDataBound.  The exact problem I am having right now is that the following line results in cboActivityID=Nothing resulting in the errors in the screenshots below...

Dim cboActivityID As RadComboBox = e.Item.FindControl("cboActivityNum")

editForm
ss.PNG
error.PNG
.aspx
<telerik:RadGrid ID="grdDetail" runat="server" CellSpacing="0" DataSourceID="sqldsDetail" DataKeyNames="TID" GridLines="None" Skin="Telerik" Height="350px" AllowSorting="True" AllowAutomaticUpdates="True" >
            <GroupingSettings CollapseAllTooltip="Collapse all groups"></GroupingSettings>
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
            <Scrolling UseStaticHeaders="True" AllowScroll="True"/>
            <Resizing AllowColumnResize="True" />
        </ClientSettings>
        <MasterTableView AutoGenerateColumns="False" DataSourceID="sqldsDetail" DataKeyNames="TID" EditMode="EditForms" AllowAutomaticUpdates="True">
            <RowIndicatorColumn Visible="true">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Created="True">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderStyle-Width="33px" />
                <telerik:GridBoundColumn DataField="TID" HeaderText="TID" ReadOnly="True" UniqueName="TID" Display="False" />
                <telerik:GridBoundColumn DataField="TranDate" HeaderText="TranDate" 
                    SortExpression="TranDate" UniqueName="TranDate" DataFormatString="{0:d}" ReadOnly="True">
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="Right" Wrap="False" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Merchant" HeaderText="Merchant"
                    SortExpression="Merchant" UniqueName="Merchant" ReadOnly="True">
                    <HeaderStyle HorizontalAlign="left" Wrap="False" />
                    <ItemStyle HorizontalAlign="left" Wrap="False" />
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Purpose" HeaderText="Purpose" 
                    SortExpression="Purpose" UniqueName="Purpose">
                    <HeaderStyle HorizontalAlign="left" Wrap="False" />
                    <ItemStyle HorizontalAlign="left" Wrap="False" />
                </telerik:GridBoundColumn>       
                <telerik:GridBoundColumn DataField="EntertainWho" HeaderText="EntertainWho" 
                    SortExpression="EntertainWho" UniqueName="EntertainWho">
                    <HeaderStyle HorizontalAlign="left" Wrap="False" />
                    <ItemStyle HorizontalAlign="left" Wrap="False" />
                </telerik:GridBoundColumn>  
                <telerik:GridBoundColumn DataField="TravelTo" HeaderText="TravelTo" 
                    SortExpression="TravelTo" UniqueName="TravelTo">
                    <HeaderStyle HorizontalAlign="left" Wrap="False" />
                    <ItemStyle HorizontalAlign="left" Wrap="False" />
                </telerik:GridBoundColumn>                                                         
                <telerik:GridBoundColumn DataField="ThirdPartyInfo" HeaderText="ThirdParty" 
                    SortExpression="ThirdPartyInfo" UniqueName="ThirdPartyInfo">
                    <HeaderStyle HorizontalAlign="left" Wrap="False" />
                    <ItemStyle HorizontalAlign="left" Wrap="False" />
                </telerik:GridBoundColumn>
<%--                <telerik:GridBoundColumn DataField="ACCT_UNIT" HeaderText="Department"
                    SortExpression="ACCT_UNIT" UniqueName="ACCT_UNIT">
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="right" Wrap="False" />
                </telerik:GridBoundColumn>--%>
                <telerik:GridTemplateColumn HeaderText="Department" UniqueName="Dept" HeaderStyle-Width="100">
                        <ItemTemplate >
                            <%#DataBinder.Eval(Container.DataItem, "ACCT_UNIT")%>
                        </ItemTemplate>
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="right" Wrap="False" />
                        <EditItemTemplate>
                            <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="cboDept" DataSourceID="sqldsDept" AutoPostBack="True"
                                DataTextField="Description" DataValueField="ENTRYID" SelectedValue='<%#Bind("ACCT_UNIT") %>' Width="500px" onselectedindexchanged="RadComboBox1_SelectedIndexChanged">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                </telerik:GridTemplateColumn>                            
                <telerik:GridTemplateColumn HeaderText="ActivityNum" UniqueName="ActivityNum" HeaderStyle-Width="100">
                        <ItemTemplate >
                            <%#DataBinder.Eval(Container.DataItem, "ActivityNum")%>
                        </ItemTemplate>
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="right" Wrap="False" />
                        <EditItemTemplate>
                            <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="cboActivityNum" Width="500px">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                 </telerik:GridTemplateColumn>
<%--                <telerik:GridBoundColumn DataField="ActivityNum" HeaderText="Activity#" 
                    SortExpression="ActivityNum" UniqueName="ActivityNum">
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="right" Wrap="False" />
                </telerik:GridBoundColumn>--%>
                <telerik:GridTemplateColumn DataField="ExpID" HeaderText="Expense" SortExpression="ExpID" UniqueName="ExpID">
                    <ItemTemplate>
                        <asp:Label ID="lblExpDesc" runat="server" Text='<%#Eval("ExpID")%>'></asp:Label>
                    </ItemTemplate>
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="right" Wrap="False" />
                        <EditItemTemplate>
                            <telerik:RadComboBox RenderMode="Lightweight" runat="server" ID="cboExpense" DataSourceID="sqldsExp"
                                DataTextField="Description" DataValueField="ExpID" SelectedValue='<%#Bind("ExpID") %>' Width="500px">
                            </telerik:RadComboBox>
                        </EditItemTemplate>
                </telerik:GridTemplateColumn>
<%--                <telerik:GridBoundColumn DataField="ExpID" HeaderText="Expense" 
                    SortExpression="ExpID" UniqueName="ExpID">
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="Right" Wrap="False" />
                </telerik:GridBoundColumn>--%>
                <telerik:GridBoundColumn DataField="TranAmt" HeaderText="TranAmt" 
                    SortExpression="TranAmt" UniqueName="TranAmt" DataFormatString="{0:c}" ReadOnly="True">
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="Right" Wrap="False" />
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn DataField="" HeaderText="Remove Split" SortExpression="" UniqueName="imgSplits" ItemStyle-HorizontalAlign="Left">
                    <ItemTemplate>
                        <asp:ImageButton ID="imgSplits" runat="server" ImageUrl="~/images/split_cell_icon.png" OnClick="imgSplits_OnClick"/>
                    </ItemTemplate>
                    <ItemStyle Wrap="False"/>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn>
                    <HeaderStyle HorizontalAlign="right" Wrap="False" />
                    <ItemStyle HorizontalAlign="Right" Wrap="False" />
                </telerik:GridTemplateColumn>
            </Columns>          
        </MasterTableView>
        </telerik:RadGrid>              

Open in new window


.aspx.vb
 Protected Sub grdDetail_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles grdDetail.ItemDataBound
        
        For Each item As GridDataItem In grdDetail.Items
            Dim sTID As String = item.GetDataKeyValue("TID").ToString()
            Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("CorpCardConnectionString").ConnectionString)
                stCon.Open()
                Dim selCommand As New SqlCommand("SELECT (e.ExpenseDesc + ' - ' + e.ExpenseNum) As ExpenseDesc FROM [CorpCard].[dbo].ExpType e JOIN [CorpCard].[dbo].Trans t ON e.ExpID=t.ExpID WHERE t.TID=@TID", stCon)
                selCommand.Parameters.Add("@TID", SqlDbType.NVarChar).Value = sTID
                Dim val As Object = selCommand.ExecuteScalar()
                If Not IsDBNull(val) Then
                    Dim sLabel As String = CType(selCommand.ExecuteScalar, String)
                    Dim lblExpDesc As Label = DirectCast(item.FindControl("lblExpDesc"), Label)
                    lblExpDesc.Text = sLabel
                End If

                'Dim selCommand0 As New SqlCommand("SELECT ACCT_UNIT FROM [Trans] WHERE TID=@TID", stCon)
                'selCommand0.Parameters.Add("@TID", SqlDbType.NVarChar).Value = sTID
                'Dim val0 As Object = selCommand0.ExecuteScalar()
                'If Not IsDBNull(val0) Then
                '    intAcctID = CInt(val0)
                'End If
                
                Dim imgSplits As ImageButton = TryCast(item.FindControl("imgSplits"), ImageButton)
                Dim selCommand2 As New SqlCommand("SELECT SplitFrom FROM [CorpCard].[dbo].[Trans] WHERE TID=@TID", stCon)
                selCommand2.Parameters.Add("@TID", SqlDbType.Int).Value = sTID
                Dim sSplitFrom As Object = selCommand2.ExecuteScalar
                If NOT IsDBNull(sSplitFrom) Then
                    imgSplits.ImageUrl = "images/split_cell_icon.png"
                Else
                    imgSplits.ImageUrl = "images/blank.png"
                End If
            End Using

        
        Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("CorpCardConnectionString").ConnectionString)
            stCon.Open()
            'Dim item As GridEditableItem = CType(e.Item, GridEditableItem)
            'Dim man2ager As GridEditManager = item.EditManager
            'Dim editor As GridTextBoxColumnEditor = CType(manager.GetColumnEditor("Dept"), GridTextBoxColumnEditor)
            'Dim cell As TableCell = editedItem("Dept")
            'Dim itemValue As String = (CType(cell.Controls(0), RadComboBox)).Text
            'For Each item As GridDataItem In grdDetail.Items
            Dim sTID2 As String = item.GetDataKeyValue("TID").ToString()
            Dim selCommand0 As New SqlCommand("SELECT ACCT_UNIT FROM [Trans] WHERE TID=@TID", stCon)
            selCommand0.Parameters.Add("@TID", SqlDbType.NVarChar).Value = sTID
            Dim val0 As Object = selCommand0.ExecuteScalar()
            If Not IsDBNull(val0) Then
                intAcctID = CInt(val0)
            End If
            'Next
        End Using

        Dim dt As DataTable = New DataTable()
        Try
            'If(TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then
                Dim editableItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
                Dim cboActivityID As RadComboBox = e.Item.FindControl("cboActivityNum")
                'Dim cboActivityID As RadComboBox = CType(editableItem("ActivityNum").FindControl("cboActivityNum"), RadComboBox)
                'Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
                'Dim cboActivityID As RadComboBox = CType(editedItem("ActivityNum").FindControl("cboActivityNum"), RadComboBox)
                'Dim selected As String = editedItem.NamingContainer.FindControl("cboActivityNum")
                'Dim str As String = editedItem.GetDataKeyValue("TID").ToString()
            
                'Dim cboDeptID As RadComboBox = TryCast((TryCast(e.Item, GridEditableItem))("Dept").Controls(0), RadComboBox)
                'Dim cboDeptID As RadComboBox = CType(sender, RadComboBox)
                'Dim selected As String = cboDeptID.SelectedValue
                'Dim cboActivityID As RadComboBox = CType(editedItem("ActivityNum").FindControl("cboActivityNum"), RadComboBox)
                'Dim connectionString As String = "Server = .; database = HKS; Integrated Security = true"
                Using stCon As New SqlConnection(ConfigurationManager.ConnectionStrings("FE_ProdConnectionString").ConnectionString)
                    Using SqlDa As SqlDataAdapter = New SqlDataAdapter("SELECT a.PROJECTID, a.DESCRIPTION + ' - ' + a.PROJECTID AS DESCRIPTION FROM GL7PROJECTS a, GL7PROJECTATTRIBUTES b, TABLEENTRIES c WHERE c.ENTRYID = '" + intAcctID.ToString() + "' AND c.CODETABLESID = 1023 AND c.TABLEENTRIESID = b.TABLEENTRIESID AND b.PARENTID = a.GL7PROJECTSID AND a.ACTIVEFLAG = 1 ORDER BY ENTRYID", stCon)
                        SqlDa.SelectCommand.CommandType = CommandType.Text
                        SqlDa.Fill(dt)
                        cboActivityID.DataSource = dt
                        cboActivityID.DataTextField = "DESCRIPTION"
                        cboActivityID.DataValueField = "PROJECTID"
                        cboActivityID.DataBind()
                    End Using
                End Using
            'End If
                Catch unusedException1 As Exception
                Throw
        End Try
        Next

    End Sub

Open in new window

AhelblingAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kumaraswamy RCommented:
protected void RadGrid10_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
 {  
       
        if((e.Item is GridEditFormItem)&&(e.Item.IsInEditMode))  
        {  
            GridEditFormItem editform = (GridEditFormItem)e.Item;  
            RadComboBox combo = (RadComboBox)editform.FindControl("RadComboBox2");  //find control
            //bind the combobox here  
            // combo.DataSource=  
            //set the selected value with key name  
            combo.SelectedValue = editform.GetDataKeyValue("ProductName").ToString();  
 
        }  
  }

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AhelblingAuthor Commented:
Thank you!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.