Hey,
I'm trying to dynamically create various levels of detail tables for a project I'm working on. I have almost everything working now (in terms of display anyway) thanks to help from this forum, but there's just one more problem. I'm trying to reference the controls in various edit/insert sections but I've hit something of a problem.
At the top level I've added a hardcoded template in the front-end code, like so:
Now I can access these controls (or could on Friday when I was trying to get it to work) in the code by trying to access them in the ItemDataBound. However when I tried to create a template, use that for the form instead in the code and then access control from there it no longer seems to work. The code I'm using to assign the template is as follows (cut down for convenience to just the relevant code):
The code for myNewAdd.ascx is just simply as follows, and it DISPLAYS absolutely fine on the form.
I'm aware the update button doesn't do anything at the moment, but at the moment I haven't gotten that far quite frankly. I'm more concerned with getting this code to work. So, I set that template as the template and it works, but when I try to access the control it doesn't work. I'm trying to access it in the ItemDataBound. Maybe I'm trying to access things in the wrong order and it's already run ItemDataBound before it's bound the template or something, in which case where do I bind the template? But here's the code I'm trying to use:
The reason I have "If Not rcbxTerminalUserGroupID Is Nothing Then" is because I was continuously getting a NullReferenceException because evidently it couldn't find the control, even though the control blatantly displays on the page. Like I said above, I'm going to assume this is because of the way that the RadGrids run the procedures possibly, or something else related to the template, but it's immensely annoying and I really want to get this working.
If anyone can help I'll be massively grateful.
                                I'm trying to dynamically create various levels of detail tables for a project I'm working on. I have almost everything working now (in terms of display anyway) thanks to help from this forum, but there's just one more problem. I'm trying to reference the controls in various edit/insert sections but I've hit something of a problem.
At the top level I've added a hardcoded template in the front-end code, like so:
<EditFormSettings EditFormType="Template">   <EditColumn UniqueName="EditCommandColumn1">   </EditColumn>   <FormTemplate>     <asp:Panel ID="pnlZForm" runat="server">       <div id="divZEdit">         <asp:Label ID="lblMerchantCode" Width="150px" runat="server" Text="Merchant Code:" />         <telerik:RadTextBox ID="rtxtMerchantCode" Runat="server" Width="150px" />         <br />         <asp:Label ID="lblAccountName" Width="150px" runat="server" Text="Account Name:" />         <telerik:RadTextBox ID="rtxtAccountName" Runat="server" Width="150px" />         <br />         <asp:Label ID="lblSharedSecret" Width="150px" runat="server" Text="Shared Secret:" />         <telerik:RadTextBox ID="rtxtSharedSecret" Runat="server" Width="150px" />         <br />         <telerik:RadButton ID="btnUpdate" runat="server" Text="Update" />         <telerik:RadButton ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" />       </div>     </asp:Panel>   </FormTemplate> </EditFormSettings>Now I can access these controls (or could on Friday when I was trying to get it to work) in the code by trying to access them in the ItemDataBound. However when I tried to create a template, use that for the form instead in the code and then access control from there it no longer seems to work. The code I'm using to assign the template is as follows (cut down for convenience to just the relevant code):
Private Sub rgdNewRadGrid_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles rgdNewRadGrid.DetailTableDataBind   Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)     Select Case e.DetailTableView.Name     Case "myDetailTable"      Dim myTrackingGUID As Guid = New Guid(dataItem.Item("MerchantTrackingGUID").Text)       Dim myDataSet As New DataSet         '===Get the DetailTable data===       myDataSet = *get dataset from database*         e.DetailTableView.DataSource = myDataSet       e.DetailTableView.CommandItemDisplay = GridCommandItemDisplay.Top       e.DetailTableView.CommandItemSettings.AddNewRecordImageUrl = "../Img/AddRecord.gif"      e.DetailTableView.CommandItemSettings.AddNewRecordText = "Add New Details"      e.DetailTableView.CommandItemSettings.ShowRefreshButton = False      e.DetailTableView.EditFormSettings.EditFormType = GridEditFormType.Template       e.DetailTableView.EditFormSettings.FormTemplate = LoadTemplate("Templates/myNewAdd.ascx")   End SelectEnd SubThe code for myNewAdd.ascx is just simply as follows, and it DISPLAYS absolutely fine on the form.
<%@ Control Language="VB" ClassName="myNewAdd" %> <asp:Panel ID="pnlNewForm" runat="server">   <div id="divNewEdit">     <asp:Label ID="lblTerminalUserGroupID" Width="150px" runat="server" Text="TerminalUserGroupID:" />     <telerik:RadComboBox ID="rcbxTerminalUserGroupID" Width="200px" runat="server" />     <br />     <telerik:RadButton ID="btnDetailUpdate" runat="server" Text="Update" />     <telerik:RadButton ID="btnDetailCancel" runat="server" Text="Cancel" CommandName="Cancel" />   </div> </asp:Panel>I'm aware the update button doesn't do anything at the moment, but at the moment I haven't gotten that far quite frankly. I'm more concerned with getting this code to work. So, I set that template as the template and it works, but when I try to access the control it doesn't work. I'm trying to access it in the ItemDataBound. Maybe I'm trying to access things in the wrong order and it's already run ItemDataBound before it's bound the template or something, in which case where do I bind the template? But here's the code I'm trying to use:
Protected Sub rgdNewRadGrid_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rgdNewRadGrid.ItemDataBound   If e.Item.IsInEditMode AndAlso e.Item.OwnerTableView.Name = "myDetailTable" Then    Dim editItem As GridEditFormItem = e.Item     Dim rcbxTerminalUserGroupID As RadComboBox = editItem.FindControl("rcbxTerminalUserGroupID")     Dim myDataSet As Data.DataSet       myDataSet = *get data from database*       For Each row As DataRow In myDataSet.Tables(0).Rows       Dim myItem As New RadComboBoxItem       myItem.Text = row.Item("NAME").ToString       If Not rcbxTerminalUserGroupID Is Nothing Then        rcbxTerminalUserGroupID.Items.Add(myItem)       End If    Next  End IfEnd SubThe reason I have "If Not rcbxTerminalUserGroupID Is Nothing Then" is because I was continuously getting a NullReferenceException because evidently it couldn't find the control, even though the control blatantly displays on the page. Like I said above, I'm going to assume this is because of the way that the RadGrids run the procedures possibly, or something else related to the template, but it's immensely annoying and I really want to get this working.
If anyone can help I'll be massively grateful.

