This is a migrated thread and some comments may be shown as answers.

Update Button in Edit Form Template Not Updating

3 Answers 515 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JW
Top achievements
Rank 1
JW asked on 21 Jan 2009, 08:32 PM
Hello,
I am new to using Telerik Controls so I am open to the idea that I have not implemented it correctly but what I am trying to do is to update rows in a RadGrid using a template edit form.  This RadGrid is bound to an ArrayList which is stored in a session variable for passing the ArrayList variable to my BLL class to perform the a batch insert which will loop through each value in the ArrayList.  But before submitting the batch I need to first update each RadGrid Row, then update the ArrayList, and re-bind it to my session variable.

So, I created the RadGrid, and have it all working fine with the ArrayList but the problem I have is that I can't seem to raise the update event inside the editform using LinkButton or Regular Button which would then update the ArrayList with the selected values in the templated edit form.  I have tried to use the "GridEditCommandColumn" both as a templated column and autogen.  I tried adding an MS Button and MS LinkButton to the Template Edit Form and could not raise the event that way either.  I have read many many support docs and searched this forum but still confused because I haven't seen this scenario described in these docs.  I have tried flipping different properties on and off but can't make any progress.  Can someone please make a suggestion or explain how to fire the update event when pressing a button inside the edit form of a RadGrid?
Thank you in advance,
JW

Here is my code example from the web page I am developing (it is only the portion pertaining to this issue)

1     <telerik:RadGrid ID="RadGrid_RCinsert" runat="server" GridLines="None"      
2                   onneeddatasource="RadGrid_RCinsert_NeedDataSource" ShowFooter="True"      
3                   ShowStatusBar="True" Skin="Office2007"      
4                   onitemcommand="RadGrid_RCinsert_ItemCommand" AutoGenerateColumns="False"      
5                   HorizontalAlign="Left"      
6                   onitemdatabound="RadGrid_RCinsert_ItemDataBound"      
7                   onitemcreated="RadGrid_RCinsert_ItemCreated"      
8                   onupdatecommand="RadGrid_RCinsert_UpdateCommand"      
9                   AllowAutomaticUpdates="True">     
10                  <HeaderContextMenu EnableTheming="True" Skin="Sunset">     
11                  <CollapseAnimation Duration="200" Type="OutQuint" />    
12                  </HeaderContextMenu>    
13                      <ItemStyle Wrap="True" />    
14                          <MasterTableView      
15                              caption="Root Cause Entry:"      
16                              datakeynames="KanbanID"      
17                              horizontalalign="Left" AllowAutomaticUpdates="False">     
18                          <RowIndicatorColumn>    
19                          <HeaderStyle Width="20px" />    
20                          </RowIndicatorColumn>    
21                          <ExpandCollapseColumn>    
22                          <HeaderStyle Width="20px" />    
23                          </ExpandCollapseColumn>    
24                          <Columns>    
25                              <telerik:GridEditCommandColumn>    
26                              </telerik:GridEditCommandColumn>    
27                              <telerik:GridTemplateColumn DataField="KanbanID" DataType="System.Int64"      
28                                  HeaderText="KanbanID" UniqueName="KanbanID">     
29                                  <EditItemTemplate>    
30                                      <asp:Label ID="lbl_KanbanID_edit" runat="server" Text='<%# Eval("KanbanID") %>'></asp:Label>    
31                                      &nbsp;     
32                                  </EditItemTemplate>    
33                                  <ItemTemplate>    
34                                      <asp:Label ID="lbl_KanbanID_item" runat="server" Text='<%# Eval("KanbanID") %>'></asp:Label>    
35                                  </ItemTemplate>    
36                              </telerik:GridTemplateColumn>    
37                              <telerik:GridTemplateColumn DataField="StOper_KBAhistID"      
38                                  HeaderText="KBAHist_ID" UniqueName="StOper_KBAhistID">     
39                                  <EditItemTemplate>    
40                                      <asp:DropDownList ID="ddl_RCStationOper_edit" runat="server"      
41                                      AppendDataBoundItems="True" DataSourceID="ods_KBAssyHistOrigErr_edit"      
42                                      DataTextField="BuiltBy" DataValueField="KBAHist_ID" AutoPostBack="True">     
43                                      <asp:ListItem Value="-1">Select a Station/Operator:</asp:ListItem>    
44                                      </asp:DropDownList>    
45                                  </EditItemTemplate>    
46                                  <ItemTemplate>    
47                                      <asp:Label ID="lbl_StOper_KBAhistID_item" runat="server"      
48                                      Text='<%# Eval("StOper_KBAhistID") %>'></asp:Label>    
49                                  </ItemTemplate>    
50                              </telerik:GridTemplateColumn>    
51                              <telerik:GridTemplateColumn DataField="LookBack " HeaderText="LookBack "      
52                                  UniqueName="LookBack ">     
53                                  <EditItemTemplate>    
54                                      <asp:DropDownList ID="ddl_LookBack_edit" runat="server" AutoPostBack="True">     
55                                          <asp:ListItem Value="N" Selected="True">No</asp:ListItem>    
56                                          <asp:ListItem Value="Y">Yes</asp:ListItem>    
57                                      </asp:DropDownList>    
58                                  </EditItemTemplate>    
59                                  <ItemTemplate>    
60                                      <asp:Label ID="lbl_LookBack_item" runat="server" Text='<%# Eval("LookBack") %>'></asp:Label>    
61                                  </ItemTemplate>    
62                             </telerik:GridTemplateColumn>    
63                             <telerik:GridTemplateColumn DataField="MissedByStOper_KBAhistID"      
64                                 HeaderText="Missed By" UniqueName="MissedByStOper_KBAhistID">     
65                                 <EditItemTemplate>    
66                                     <asp:DropDownList ID="ddl_MissedByStOper_KBAhistID_edit" runat="server"      
67                                     AppendDataBoundItems="True" DataSourceID="ods_MissedByKBAssyHistOrigErr_edit"      
68                                     DataTextField="BuiltBy" DataValueField="KBAHist_ID" AutoPostBack="True">     
69                                     <asp:ListItem Value="-1">Select a Station/Operator:</asp:ListItem>    
70                                     </asp:DropDownList>    
71                         </EditItemTemplate>    
72                         <ItemTemplate>    
73                             <asp:Label ID="lbl_MissedByStOper_KBAhistID_item" runat="server"      
74                             Text='<%# Eval("MissedByStOper_KBAhistID") %>'></asp:Label>    
75                         </ItemTemplate>    
76                         </telerik:GridTemplateColumn>    
77                         <telerik:GridTemplateColumn DataField="Inspection_LookBack"      
78                             HeaderText="Inspection_LookBack" UniqueName="Inspection_LookBack">     
79                         <EditItemTemplate>    
80                             <asp:DropDownList ID="ddl_InspLookBack_edit" runat="server"      
81                                 AppendDataBoundItems="True" AutoPostBack="True">     
82                                 <asp:ListItem Value="N">No</asp:ListItem>    
83                                 <asp:ListItem Value="Y">Yes</asp:ListItem>                                                                           
84                             </asp:DropDownList>    
85                         </EditItemTemplate>    
86                         <ItemTemplate>    
87                             <asp:Label ID="lbl_Inspection_LookBack_item" runat="server"      
88                             Text='<%# Eval("Inspection_LookBack") %>'></asp:Label>    
89                         </ItemTemplate>    
90                     </telerik:GridTemplateColumn>    
91                     <telerik:GridTemplateColumn DataField="Scrapped " HeaderText="Scrapped "      
92                            UniqueName="Scrapped ">     
93                        <EditItemTemplate>    
94                             <asp:DropDownList ID="ddl_Scrapped_edit" runat="server"      
95                                 AppendDataBoundItems="True" AutoPostBack="True">     
96                                 <asp:ListItem Value="N">No</asp:ListItem>    
97                                 <asp:ListItem Value="Y">Yes</asp:ListItem>    
98                             </asp:DropDownList>    
99                        </EditItemTemplate>    
100                       <ItemTemplate>    
101                            <asp:Label ID="lbl_Scrapped_item" runat="server" Text='<%# Eval("Scrapped") %>'></asp:Label>    
102                        </ItemTemplate>    
103                  </telerik:GridTemplateColumn>    
104                      </Columns>    
105                      <EditFormSettings EditFormType="Template">     
106                         <EditColumn ButtonType="ImageButton" UniqueName="EditCommandColumn1">     
107                         </EditColumn>    
108                         <FormCaptionStyle Font-Bold="True" Font-Size="X-Small" ForeColor="Red" />    
109                            <FormTemplate>    
110                                <asp:Label ID="lbl_KanbanID_edit" runat="server" ForeColor="Blue"      
111                                      Text='<%# Eval("KanbanID") %>'></asp:Label>    
112                                <br />    
113                                  Root Cause Station/Operator:&nbsp;     
114                                  <asp:DropDownList ID="ddl_RCStationOper_edit" runat="server"      
115                                      AppendDataBoundItems="True" AutoPostBack="True"      
116                                      DataSourceID="ods_KBAssyHistOrigErr_edit" DataTextField="BuiltBy"      
117                                      DataValueField="KBAHist_ID">     
118                                  <asp:ListItem Value="-1">Select a Station/Operator:</asp:ListItem>    
119                              </asp:DropDownList>    
120                              <br />    
121                              LookBack?&nbsp;     
122                              <asp:DropDownList ID="ddl_LookBack_edit" runat="server" AutoPostBack="True">     
123                                  <asp:ListItem Value="N">No</asp:ListItem>    
124                                  <asp:ListItem Value="Y">Yes</asp:ListItem>    
125                              </asp:DropDownList>    
126                              <br />    
127                              Missed By Station/Operator:&nbsp;     
128                              <asp:DropDownList ID="ddl_MissedByStOper_KBAhistID_edit" runat="server"      
129                                  AppendDataBoundItems="True" AutoPostBack="True"      
130                                  DataSourceID="ods_MissedByKBAssyHistOrigErr_edit" DataTextField="BuiltBy"      
131                                  DataValueField="KBAHist_ID">     
132                                  <asp:ListItem Value="-1">Select a Station/Operator:</asp:ListItem>    
133                              </asp:DropDownList>    
134                              <br />    
135                              Inspection LookBack:&nbsp;     
136                              <asp:DropDownList ID="ddl_InspLookBack_edit" runat="server"      
137                                  AppendDataBoundItems="True" AutoPostBack="True">     
138                                  <asp:ListItem Value="N">No</asp:ListItem>    
139                                  <asp:ListItem Value="Y">Yes</asp:ListItem>    
140                              </asp:DropDownList>    
141                              <br />    
142                              Scrapped?&nbsp;     
143                              <asp:DropDownList ID="ddl_Scrapped_edit" runat="server"      
144                                  AppendDataBoundItems="True" AutoPostBack="True">     
145                                  <asp:ListItem Value="N">No</asp:ListItem>    
146                                  <asp:ListItem Value="Y">Yes</asp:ListItem>    
147                              </asp:DropDownList>    
148                              <br />    
149                              <asp:LinkButton ID="LinkBtn_Update" runat="server" CommandName="Update"      
150                                  onclick="LinkBtn_Update_Click">Update</asp:LinkButton>    
151                              <br />    
152                            </FormTemplate>    
153                            <PopUpSettings Width="600px" />    
154                            </EditFormSettings>    
155                            <EditItemStyle BackColor="#FFCC99" />    
156                         </MasterTableView>    
157                         <ClientSettings EnablePostBackOnRowClick="True">     
158                         </ClientSettings>    
159                         <FilterMenu EnableTheming="True" Skin="Sunset">     
160                             <CollapseAnimation Duration="200" Type="OutQuint" />    
161                         </FilterMenu>    
162     </telerik:RadGrid>   
 
163     <asp:ObjectDataSource ID="ods_KBAssyHistOrigErr_edit" runat="server"      
164                       DeleteMethod="DeleteKBAssyHist" InsertMethod="AddKBAssyHist"      
165                       OldValuesParameterFormatString="original_{0}" SelectMethod="GetKBAssyHist_KBID"      
166                       TypeName="KBAssemblyHist" UpdateMethod="UpdateKBAssyHist">     
167                       <DeleteParameters>    
168                           <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
169                       </DeleteParameters>    
170                       <UpdateParameters>    
171                           <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
172                           <asp:Parameter Name="Emp_ID" Type="Int32" />    
173                           <asp:Parameter Name="KBAHist_LastUpdatedStamp" Type="DateTime" />    
174                           <asp:Parameter Name="KBAHist_LastUpdatedBy" Type="Int32" />    
175                           </UpdateParameters>    
176                       <SelectParameters>    
177                           <asp:Parameter DefaultValue="-1" Name="KB_ID" Type="Int64" />    
178                       </SelectParameters>    
179                       <InsertParameters>    
180                            <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
181                            <asp:Parameter Name="KB_ID" Type="Int64" />    
182                            <asp:Parameter Name="St_ID" Type="Int32" />    
183                            <asp:Parameter Name="Emp_ID" Type="Int32" />    
184                            <asp:Parameter Name="KBAHist_ts" Type="DateTime" />    
185                            <asp:Parameter Name="KBAHist_LastUpdatedStamp" Type="DateTime" />    
186                            <asp:Parameter Name="KBAHist_LastUpdatedBy" Type="Int32" />    
187                        </InsertParameters>    
188     </asp:ObjectDataSource>    
189     <asp:ObjectDataSource ID="ods_MissedByKBAssyHistOrigErr_edit" runat="server"      
190                       DeleteMethod="DeleteKBAssyHist" InsertMethod="AddKBAssyHist"      
191                       OldValuesParameterFormatString="original_{0}" SelectMethod="GetKBAssyHist_KBID"      
192                       TypeName="KBAssemblyHist" UpdateMethod="UpdateKBAssyHist">     
193                       <DeleteParameters>    
194                           <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
195                       </DeleteParameters>    
196                       <UpdateParameters>    
197                           <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
198                           <asp:Parameter Name="Emp_ID" Type="Int32" />    
199                           <asp:Parameter Name="KBAHist_LastUpdatedStamp" Type="DateTime" />    
200                           <asp:Parameter Name="KBAHist_LastUpdatedBy" Type="Int32" />    
201                       </UpdateParameters>    
202                       <SelectParameters>    
203                           <asp:Parameter DefaultValue="-1" Name="KB_ID" Type="Int64" />    
204                       </SelectParameters>    
205                       <InsertParameters>    
206                           <asp:Parameter Name="KBAHist_ID" Type="Int64" />    
207                           <asp:Parameter Name="KB_ID" Type="Int64" />    
208                           <asp:Parameter Name="St_ID" Type="Int32" />    
209                           <asp:Parameter Name="Emp_ID" Type="Int32" />    
210                           <asp:Parameter Name="KBAHist_ts" Type="DateTime" />    
211                           <asp:Parameter Name="KBAHist_LastUpdatedStamp" Type="DateTime" />    
212                           <asp:Parameter Name="KBAHist_LastUpdatedBy" Type="Int32" />    
213                       </InsertParameters>    
214     </asp:ObjectDataSource>
                                                                         
 


    Protected Sub RadGrid_RCinsert_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs)  
        'Bind RootCause Insert radgrid to session var containing selected kbids:  
        Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
        If Not Session("RCList_Array"Is Nothing Then 
            rootcauseList_Array = Session("RCList_Array")  
        End If 
        If Not RadGrid_RCinsert Is Nothing Then 
            If Not rootcauseList_Array Is Nothing Then 
                'this is the old method where I bound the RadGrid to the ArrayList directly.  
                RadGrid_RCinsert.DataSource = rootcauseList_Array  
            End If 
        End If 
    End Sub 
    Protected Sub RadGrid_RCinsert_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs)  
        If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then 
            Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim strKBID As String = item.GetDataKeyValue("KanbanID").ToString  
            kbid_num = CType(strKBID, Long)    'getting error:"Conversion from string "objRootCauseRecordInsert" to type 'Long' is not valid."  
            'Display current selected row's KBID for testing purposes:  
            ' Dim RadAjaxManager1 As RadAjaxManager = FormView1.FindControl("RadAjaxManager1")  
            ' RadAjaxManager1.Alert("selected row strKBID:  " + strKBID)  
 
            'set up session variable to hold arraylist object: (otherwise only one item is added to arrylist)  
            If Not Session("RCList_Array"Is Nothing Then 
                rootcauseList_Array = Session("RCList_Array")  
            End If 
 
            'Define RADGridRow's MS DropDownList objects:  
            Dim ddl_RCStationOper_edit As DropDownList = CType(item.FindControl("ddl_RCStationOper_edit"), DropDownList)  
            Dim ddl_MissedByStOper_KBAhistID_edit As DropDownList = CType(item.FindControl("ddl_MissedByStOper_KBAhistID_edit"), DropDownList)  
            Dim ddl_LookBack_edit As DropDownList = CType(item.FindControl("ddl_LookBack_edit"), DropDownList)  
            Dim ddl_InspLookBack_edit As DropDownList = CType(item.FindControl("ddl_InspLookBack_edit"), DropDownList)  
            Dim ddl_Scrapped_edit As DropDownList = CType(item.FindControl("ddl_Scrapped_edit"), DropDownList)  
 
            'Set current row's Kanban ID to the default select param of ods for ddl root cause oper:  
            Dim ods_KBAssyHistOrigErr_edit As ObjectDataSource = FormView1.FindControl("ods_KBAssyHistOrigErr_edit")  
            If Not ods_KBAssyHistOrigErr_edit Is Nothing Then 
                ods_KBAssyHistOrigErr_edit.SelectParameters("KB_ID").DefaultValue = kbid_num  
                ods_KBAssyHistOrigErr_edit.DataBind()  
            End If 
            ddl_RCStationOper_edit.DataBind()  
            Dim item_count As New Integer 
            item_count = ddl_RCStationOper_edit.Items.Count  
            If item_count = 0 Then 
                ddl_RCStationOper_edit.Items.Clear()  
                ddl_RCStationOper_edit.Items.Insert(0, New ListItem("No Assembly History Recorded for this Kanban""-1"))  
                ddl_RCStationOper_edit.SelectedValue = -1  
                ddl_RCStationOper_edit.DataBind()  
            End If 
 
 
            'Set current row's Kanban ID to the default select param of ods for ddl missed by oper:  
            Dim ods_MissedByKBAssyHistOrigErr_edit As ObjectDataSource = FormView1.FindControl("ods_MissedByKBAssyHistOrigErr_edit")  
            If Not ods_MissedByKBAssyHistOrigErr_edit Is Nothing Then 
                ods_MissedByKBAssyHistOrigErr_edit.SelectParameters("KB_ID").DefaultValue = kbid_num  
                ods_MissedByKBAssyHistOrigErr_edit.DataBind()  
            End If 
            ddl_MissedByStOper_KBAhistID_edit.DataBind()  
            Dim item_count2 As New Integer 
            item_count2 = ddl_RCStationOper_edit.Items.Count  
            If item_count2 = 0 Then 
                ddl_RCStationOper_edit.Items.Clear()  
                ddl_RCStationOper_edit.Items.Insert(0, New ListItem("No Assembly History Recorded for this Kanban""-1"))  
                ddl_RCStationOper_edit.SelectedValue = -1  
                ddl_RCStationOper_edit.DataBind()  
            End If 
 
 
            'reset session variable to redefine kbidList_Array  
            Session("RCList_Array") = rootcauseList_Array  
 
            'Bind RootCause Insert radgrid to session var containing selected kbids:  
            Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
            If Not Session("RCList_Array"Is Nothing Then 
                rootcauseList_Array = Session("RCList_Array")  
            End If 
            If Not RadGrid_RCinsert Is Nothing Then 
                RadGrid_RCinsert.DataSource = rootcauseList_Array  
            End If 
 
        End If 
    End Sub 
 
    Protected Sub RadGrid_RCinsert_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs)  
 
    End Sub 
 
    Protected Sub RadGrid_RCinsert_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs)  
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
        Dim strKBID As String = editedItem.GetDataKeyValue("KanbanID").ToString  
        Dim RadGrid_RCinsert As RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
 
        'If (e.Item.IsInEditMode) Then  
 
        If (e.CommandName = "Update"Then 
 
            ' If (e.CommandName = RadGrid.UpdateCommandName) Then  
            'If e.Item.IsInEditMode = True Then  
            'Display current row's KanbanID for testing purposes:  
            'Dim RadAjaxManager1 As RadAjaxManager = FormView1.FindControl("RadAjaxManager1")  
            'RadAjaxManager1.Alert("selected row strKBID:  " + strKBID)  
 
            'extract values from each dropdownlist in the current selected row in gridcolumns:  
            'set up session vars to hold selected values from MS dropdownlists:  
            Session("sessKanbanID_currRow") = CType(strKBID, Long)  
 
            'ex: CType(editedItem.FindControl(""), DropDownList).SelectedItem.Value  
            'Root Cause Station Operator KBAHist_ID:  
            Dim ddl_RCStationOper_edit As DropDownList = CType(editedItem.FindControl("ddl_RCStationOper_edit"), DropDownList)  
            Dim selected_RCStationOper As String = ddl_RCStationOper_edit.SelectedItem.Value  
            Session("sessRCStationOper_updated") = CType(selected_RCStationOper, Long)  
 
            'Missed By Station Operator KBAHist_ID:  
            Dim ddl_MissedByStOper_KBAhistID_edit As DropDownList = CType(editedItem.FindControl("ddl_MissedByStOper_KBAhistID_edit"), DropDownList)  
            Dim selected_MissedByStationOper As String = ddl_MissedByStOper_KBAhistID_edit.SelectedValue  
            Session("sessMissedBy_updated") = CType(selected_MissedByStationOper, Long)  
 
            'LookBack?  
            Dim ddl_LookBack_edit As DropDownList = CType(editedItem.FindControl("ddl_LookBack_edit"), DropDownList)  
            Dim selected_LookBack As String = ddl_LookBack_edit.SelectedValue  
            Session("sessLookBack_updated") = selected_LookBack  
 
            'Inspector LookBack?  
            Dim ddl_InspLookBack_edit As DropDownList = CType(editedItem.FindControl("ddl_InspLookBack_edit"), DropDownList)  
            Dim selected_InspLB As String = ddl_InspLookBack_edit.SelectedValue  
            Session("sessInspectionLookBack_updated") = selected_InspLB  
 
            'Scrapped?  
            Dim ddl_Scrapped_edit As DropDownList = CType(editedItem.FindControl("ddl_Scrapped_edit"), DropDownList)  
            Dim selected_Scrapped As String = ddl_Scrapped_edit.SelectedValue  
            Session("sessScrapped_updated") = selected_Scrapped  
 
            Dim selected_KBID As Long 
            Dim updated_StOper_KBAhistID As Long 
            Dim updated_LookBack As String 
            Dim updated_MissedByStOper_KBAhistID As Long 
            Dim updated_Inspection_LookBack As String 
            Dim updated_Scrapped As String 
 
            selected_KBID = Session("sessKanbanID_currRow")  
            updated_StOper_KBAhistID = Session("sessRCStationOper_updated")  
            updated_LookBack = Session("sessLookBack_updated")  
            updated_MissedByStOper_KBAhistID = Session("sessMissedBy_updated")  
            updated_Inspection_LookBack = Session("sessInspectionLookBack_updated")  
            updated_Scrapped = Session("sessScrapped_updated"


             'More to add here to update ArrayList - just trying to fire event successfully first.

 
 
        End If 
    End Sub 

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 26 Jan 2009, 01:30 PM
Hello JW,

Here are some notes that I hope will prove helpful to you:

1. In order to use a tempated edit form you have to set the "EditMode" attribute of the MasterTableView to "EditForms".

2. For two way binding of templated colums, you have to used the "Bind" method, not the "Eval".

3. You don't need to specify an event handler for the link button in the templated edit form. So you should remove the "onclick="LinkBtn_Update_Click"" attribute from the tag. Since the CommandName of the button is set to "Update" it will automatically trigger an update operation. If you need to perform additional check and operations, intercept the ItemCommand event, check that the CommandName is "Update" and implement whatever extra business logic is necessary.

Hope this helps,
Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
JW
Top achievements
Rank 1
answered on 26 Jan 2009, 11:27 PM

Hello Tsvetoslav:
Thank you for your reply I appreciate your time.

I do have the edit mode set to "editform".   And for the two way binding, I only have a few labels set to "Eval" to display a readonly version of the data.  I didn't think that two-way binding against an arraylist would work which is why I didn't use "Bind".  But maybe I am wrong? 

I tried adding it back and I just get error messages.  Could you could explain why I get this error message when using "Bind":
"Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control."

I had just added that onclick event to the button as part of my many attempts to get the darn button to fire the update event.  I have removed it now.

I did however, find the root cause problem to my update command not executing!  It was due to 3 Rad Spell Checkers I had placed on the last three multiline textboxes on the page (which were not inside the rad grid or related to the grid at all).  Once I removed all three - viola!  The update command on the radgrid would execute.  If other's are struggling with this same problem I would suggest removing any RadSpell's and see if that helps you out.

But now I have another problem....
Whenever I hit the update button, and the update command executes, and re-binds the arraylist to the radgrid I end up with only the one edited item in my arraylist and all the items/rows are just gone.  I am wondering if I need to either try the two-way binding or come up with a way to save the existing items in my RadGrid/arraylist (maybe it requires the use of a hashtable)? 
Any suggestions?


KanbanID = key value
Kanban  = key text value
RootCause_StOper 
LookBack
MissedBy_StOper
InspectionLBMissedBy_StOper
Scrapped
RootCause_StOper_Name
MissedBy_StOper_Name
InspectionLBMissedBy_StOper_Name

Here is a description the functionality of this page and the order of events:
The user enters a part number and clicks the "GO" button.
A checkbox list is populated with kanban numbers to select.  Upon checking or unchecking the checkboxlist items the funciton "Count_ALL_ListItems"  is called to build an arraylist named "rootcauseList_Array".  The key field is "KanbanID" which will be master list of reocords to be submitted as a batch insert to a defect tracking database.  The RadGrid that is causing me trouble, "RadGrid_RCinsert", which is meant to be the tool the for the person entering this batch of defect records to easily update the values for the rootcause fields in the "rootcauseList_Array".  This RadGrid is initialized with the selected kanbans id's and default values for the rest of the fields in the object named "objDefectRootCauseRec" used to build the "rootcauseList_Array" arraylist.  The RadGrid_RCinsert is set up to allow them to add more information about who or what really caused the defect during assembly of the unit which involves selecting values for the following template bound columns in the grid:
KanbanID = key value - not editable
Kanban  = key text value - not editable (for display only)
RootCause_StOper 
LookBack
MissedBy_StOper
InspectionLBMissedBy_StOper
Scrapped
RootCause_StOper_Name
MissedBy_StOper_Name
InspectionLBMissedBy_StOper_Name

Below is the entire Code-Behind so you know the "whole story" but the RadGrid I am speaking about is at the bottom of the page and is named "RadGrid_RCinsert".   I tried to also add the ASPX but there seemed to be a problem with a "long running script" and I could not submit it with this post.  Let me know if you need it and I can try posting it again later.

Imports System.Text.StringBuilder  
Imports System.Data  
Imports System.Data.SqlClient  
Imports System.Data.SqlDbType  
Imports System.EventArgs  
Imports System.Threading  
Imports System.Collections  
Imports System.Collections.Generic  
Imports DAL_DupDefects_withRootCause  
Imports DAL_DupDefects_withRootCauseTableAdapters  
Imports Telerik.Web  
Imports Telerik.Web.UI  
 
Partial Class Defects_BatchEntry_DefectsAndRootCause  
    Inherits System.Web.UI.Page  
 
    Dim refDesList_Array As New ArrayList  
    Dim kbidList_Array As New ArrayList  
    Dim rootcauseList_Array As New ArrayList  
    Dim kbid_num As Long 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        'if session vars weren't setup yet redirect user to home page:  
        If Session("sessCurrOp_ID") = Nothing Then 
            Page.Response.Redirect("~/Default.aspx")  
        End If 
 
        If Not (Thread.CurrentPrincipal.IsInRole("IS-BusSystems") = TrueThen 
            Page.Response.Redirect("~/AccessDenied.aspx")  
        End If 
 
        Page.MaintainScrollPositionOnPostBack = True 
        lbl_SubmissionMsg.Text = "" 
        lbl_ExceptionDetails.Visible = False 
 
        If Not Page.IsPostBack Then 
            Dim txt_Assembly As TextBox = FormView1.FindControl("txt_Assembly")  
            txt_Assembly.Focus()  
            Dim lbl_EmptyDataList As Label = FormView1.FindControl("lbl_EmptyDataList")  
            lbl_EmptyDataList.Text = "" 
            Dim CheckBoxList1 As CheckBoxList = FormView1.FindControl("CheckBoxList1")  
            CheckBoxList1.DataSourceID = "" 
            CheckBoxList1.DataBind()  
 
            'Dim lbl_ResponseMsg As Label = FormView1.FindControl("lbl_ResponseMsg")  
            Dim lbl_totalItemsSelected As Label = FormView1.FindControl("lbl_totalItemsSelected")  
            'lbl_ResponseMsg.Text = ""  
 
            Dim lbl_TotalSelected As Label = FormView1.FindControl("lbl_TotalSelected")  
            lbl_TotalSelected.ForeColor = Drawing.Color.Black  
            lbl_TotalSelected.Font.Bold = True 
            lbl_TotalSelected.Text = "Total Selected: " 
            lbl_totalItemsSelected.Text = "0" 
 
            'when page first loads be sure both array lists are cleared.  
            Clear_RefListArray(sender, e)  
            Clear_KBListArray(sender, e)  
            Clear_RootCauseListArray(sender, e)  
        End If 
 
    End Sub 
    Protected Sub CheckBoxList1_DataBound(ByVal sender As ObjectByVal e As System.EventArgs)  
        Count_ALL_ListItems(sender, e)  
        Count_CheckedListItems(sender, e)  
    End Sub 
    Protected Sub CheckBoxList1_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        'update counters:  
        Count_CheckedListItems(sender, e)  
    End Sub 
    Private Sub ClearSessionVars_currRow()  
        Session("sessKanbanID_currRow") = Nothing 
        Session("sessKanban_currRow") = Nothing 
        Session("sessRCStationOper_updated") = Nothing 
        Session("sessLookBack_updated") = Nothing 
        Session("sessMissedBy_updated") = Nothing 
        Session("sessInspectionLookBackMissedBy_updated") = Nothing 
        Session("sessScrapped_updated") = Nothing 
        Session("sessRCStationOperName_updated") = Nothing 
        Session("sessMissedByName_updated") = Nothing 
        Session("sessInspLBMissedByName_updated") = Nothing 
    End Sub 
    Private Sub Clear_KBListArray(ByVal sender As ObjectByVal e As EventArgs)  
        Session("KBList_Array") = Nothing 
        kbidList_Array = Session("KBList_Array")  
    End Sub 
    Private Sub Clear_RefListArray(ByVal sender As ObjectByVal e As EventArgs)  
        Session("RefList_Array") = Nothing 
        refDesList_Array = Session("RefList_Array")  
 
        'bind ArrayList to GridView:  
        Dim RadGrid_SelectedRefsList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_SelectedRefsList")  
        RadGrid_SelectedRefsList.DataSource = refDesList_Array  
        RadGrid_SelectedRefsList.DataBind()  
    End Sub 
    Private Sub Clear_RootCauseListArray(ByVal sender As ObjectByVal e As EventArgs)  
        Session("RCList_Array") = Nothing 
        rootcauseList_Array = Session("RCList_Array")  
 
        'bind ArrayList to GridView:  
        Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
        RadGrid_RCinsert.DataSource = rootcauseList_Array  
        RadGrid_RCinsert.Rebind()  
    End Sub 
    Private Sub Count_ALL_ListItems(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim cnt_ALL As New Integer 
        Dim CheckBoxList1 As CheckBoxList = FormView1.FindControl("CheckBoxList1")  
        Dim lbl_totalRows As Label = FormView1.FindControl("lbl_totalRows")  
        Dim lbl_EmptyDataList As Label = FormView1.FindControl("lbl_EmptyDataList")  
        cnt_ALL = CheckBoxList1.Items.Count  
        lbl_totalRows.Text = cnt_ALL.ToString  
        lbl_EmptyDataList.Text = "" 
 
        If CheckBoxList1.Items.Count = 0 Then 
            'lbl_EmptyDataList.Visible = True  
            lbl_EmptyDataList.Text = "Sorry, no kanbans available for that assembly." 
        End If 
    End Sub 
    Private Sub Count_CheckedListItems(ByVal sender As ObjectByVal e As System.EventArgs)  
        'variables for building and reading arraylist:  
        Dim checked_rowcnt As New Integer 
        Dim selected_KBID As New Long 
        Dim selected_Kanban As String = "" 
        Dim output As String = Nothing 
        Dim CheckBoxList1 As CheckBoxList = FormView1.FindControl("CheckBoxList1")  
        Dim lbl_TotalSelected As Label = FormView1.FindControl("lbl_TotalSelected")  
        Dim lbl_totalItemsSelected As Label = FormView1.FindControl("lbl_totalItemsSelected")  
 
        'variables to populate arraylist object:  
        Dim KanbanID As Long 
        Dim Kanban As String 
        Dim RootCause_StOper As Long 
        Dim LookBack As String 
        Dim MissedBy_StOper As Long 
        Dim InspectionLBMissedBy_StOper As Long 
        Dim Scrapped As String 
        Dim RootCause_StOper_Name As String 
        Dim MissedBy_StOper_Name As String 
        Dim InspectionLBMissedBy_StOper_Name As String 
 
        'add selected ref to listbox:  
        If Not CheckBoxList1 Is Nothing Then 
            'destroy session var and rebuild, and reset label that displays session var:  
            Dim kbidList_Array As New ArrayList  
            Dim rootcauseList_Array As New ArrayList  
 
            'Clear existing array lists so items are not being added multiple times.  
            Clear_KBListArray(sender, e)  
            Clear_RootCauseListArray(sender, e)  
 
            'Populate array with selected checkboxes:  
            If CheckBoxList1.SelectedIndex = -1 Then 
                output = ("No kanbans Selected")  
                selected_KBID = 0  
                lbl_TotalSelected.ForeColor = Drawing.Color.Red  
                lbl_TotalSelected.Font.Bold = True 
                lbl_TotalSelected.Text = output  
                lbl_totalItemsSelected.Text = selected_KBID  
            Else 
                'loop through each row and add checked rows to listbox:  
                For Each i As ListItem In CheckBoxList1.Items  
                    If i.Selected = True Then 
                        selected_KBID = i.Value  
                        selected_Kanban = Trim(i.Text.ToString)  
                        'add selected kanbanID to RootCause Insert RadGrid and create new radgrid row with default values:  
                        KanbanID = selected_KBID  
                        Kanban = selected_Kanban  
                        RootCause_StOper = -1  
                        LookBack = "N" 
                        MissedBy_StOper = -1  
                        InspectionLBMissedBy_StOper = -1  
                        Scrapped = "N" 
                        RootCause_StOper_Name = "" 
                        MissedBy_StOper_Name = "" 
                        InspectionLBMissedBy_StOper_Name = "" 
 
                        'set up session variable to hold arraylist object: (otherwise only one item is added to arrylist)  
                        If Not Session("KBList_Array"Is Nothing Then 
                            kbidList_Array = Session("KBList_Array")  
                        End If 
 
                        If Not Session("RCList_Array"Is Nothing Then 
                            rootcauseList_Array = Session("RCList_Array")  
                        End If 
 
                        'add new arraylist item to array object and append to session var:(use object to fill in values in new instance of listitem):   
                        kbidList_Array.Add(New objKBIDListItem(selected_KBID, selected_Kanban))  
                        'add new arraylist item to array object and append to session var:  
 
                        rootcauseList_Array.Add(New objDefectRootCauseRec( _  
                                                KanbanID, _  
                                                Kanban, _  
                                                RootCause_StOper, _  
                                                LookBack, _  
                                                MissedBy_StOper, _  
                                                InspectionLBMissedBy_StOper, _  
                                                Scrapped, _  
                                                RootCause_StOper_Name, _  
                                                MissedBy_StOper_Name, _  
                                                InspectionLBMissedBy_StOper_Name))  
 
 
 
 
                        'update counter:  
                        checked_rowcnt = checked_rowcnt + 1  
                    End If 
                Next 
 
                'reset session variable to redefine kbidList_Array  
                Session("KBList_Array") = kbidList_Array  
                Session("RCList_Array") = rootcauseList_Array  
 
                'update labels/displays:  
                lbl_TotalSelected.ForeColor = Drawing.Color.Black  
                lbl_TotalSelected.Font.Bold = True 
                lbl_TotalSelected.Text = "Total Selected: " 
                lbl_totalItemsSelected.Text = "0" 
                lbl_totalItemsSelected.Text = checked_rowcnt.ToString()  
            End If 
 
            'Bind RootCause Insert radgrid to session var containing selected kbids:  
            Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
            If Not RadGrid_RCinsert Is Nothing Then 
                RadGrid_RCinsert.DataSource = rootcauseList_Array  
                RadGrid_RCinsert.DataBind()  
            End If 
        End If 
 
    End Sub 
    Protected Sub btn_AddNewDefect_Click(ByVal sender As ObjectByVal e As System.EventArgs)  
        'Dim ListBox_SelectedKanbans As ListBox = FormView1.Row.FindControl("ListBox_SelectedKanbans")  
        Dim ods_AddDupDefects_withRC As ObjectDataSource = FormView1.Row.FindControl("ods_AddDupDefects_withRC")  
 
        If Page.IsValid = True Then 
            'call insert method:  
            ods_AddDupDefects_withRC.Insert()  
        End If 
 
    End Sub 
    Protected Sub btn_ResetForm_Click(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim txt_Assembly As TextBox = FormView1.FindControl("txt_Assembly")  
        Dim lbl_totalItemsSelected As Label = FormView1.FindControl("lbl_totalItemsSelected")  
 
        txt_Assembly.Text = "" 
        lbl_totalItemsSelected.Text = "" 
 
        'clear arraylist of references:  
        Clear_RefListArray(sender, e)  
        Clear_KBListArray(sender, e)  
        Clear_RootCauseListArray(sender, e)  
    End Sub 
    Protected Sub btn_GO_Click(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim CheckBoxList1 As CheckBoxList = FormView1.FindControl("CheckBoxList1")  
        'clear arraylist of references:  
        Clear_RefListArray(sender, e)  
        Clear_KBListArray(sender, e)  
        Clear_RootCauseListArray(sender, e)  
 
        'count kanbans available and update label:  
        Count_ALL_ListItems(sender, e)  
 
        CheckBoxList1.DataSourceID = "ods_KanbanList" 
        CheckBoxList1.DataBind()  
    End Sub 
    Protected Sub txt_Assembly_TextChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim lbl_KanbansSelected As Label = FormView1.FindControl("lbl_KanbansSelected")  
        Dim GridView_SelectedKanbans As GridView = FormView1.FindControl("GridView_SelectedKanbans")  
        Dim CheckBoxList1 As CheckBoxList = FormView1.FindControl("CheckBoxList1")  
        Dim lbl_totalItemsSelected As Label = FormView1.FindControl("lbl_totalItemsSelected")  
 
        CheckBoxList1.DataSourceID = "" 
        CheckBoxList1.DataBind()  
        lbl_totalItemsSelected.Text = "0" 
 
        'clear arraylist of references:  
        Clear_KBListArray(sender, e)  
        Clear_RefListArray(sender, e)  
        Clear_RootCauseListArray(sender, e)  
 
 
    End Sub
#Region "FormView1"  
    Protected Sub FormView1_DataBound(ByVal sender As ObjectByVal e As System.EventArgs) Handles FormView1.DataBound  
        '************************  
        ' INSERT MODE:  
        '************************  
        If FormView1.CurrentMode = FormViewMode.Insert Then 
            'Set initial values of DDLs when form loads in insert mode:  
            'Dept Found Error:  
            Dim ddl_DeptFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_DeptFoundErr_insert"), DropDownList)  
            ddl_DeptFoundErr.DataBind()  
            ddl_DeptFoundErr.Items.Insert(0, New ListItem("Select Department""-1"))  
            ddl_DeptFoundErr.SelectedValue = -1  
 
            'Line Segment Found Error:  
            Dim ddl_LineSegFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_LineSegFoundErr_insert"), DropDownList)  
            ddl_LineSegFoundErr.DataBind()  
            'ddl_LineSegFoundErr.Items.Clear()  
            ddl_LineSegFoundErr.Items.Insert(0, New ListItem("Select Line Segment""-1"))  
            ddl_LineSegFoundErr.SelectedValue = -1  
 
            'Operator Found Error:  
            Dim ddl_OpFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_OpFoundErr_insert"), DropDownList)  
            ddl_OpFoundErr.DataBind()  
            'ddl_OpFoundErr.Items.Clear()  
            ddl_OpFoundErr.Items.Insert(0, New ListItem("Select Operator""-1"))  
            ddl_OpFoundErr.SelectedValue = -1  
 
            'Dept Source Err:  
            Dim ddl_DeptSourceErr As DropDownList = CType(FormView1.Row.FindControl("ddl_DeptSourceErr_Insert"), DropDownList)  
            ddl_DeptSourceErr.Items.Insert(0, New ListItem("Select Department""-1"))  
            ddl_DeptSourceErr.SelectedValue = -1  
 
            'Defect Codes:  
            Dim ddl_DefectCodes As DropDownList = CType(FormView1.Row.FindControl("ddl_DefectCodes_insert"), DropDownList)  
            ddl_DefectCodes.DataBind()  
            'ddl_DefectCodes.Items.Clear()  
            ddl_DefectCodes.Items.Insert(0, New ListItem("Select Defect Code""-1"))  
            ddl_DefectCodes.SelectedValue = -1  
 
            'Cause Codes    
            Dim ddl_CauseCodeList As DropDownList = FormView1.FindControl("ddl_CauseCodeList_insert")  
            ddl_CauseCodeList.Items.Clear()  
            ddl_CauseCodeList.Items.Insert(0, New ListItem("Select Cause Code""-1"))  
            ddl_CauseCodeList.SelectedValue = -1  
 
            'Cause Codes TYPE:  
            'Dim ddl_SelectedCauseCodeType As DropDownList = FormView1.FindControl("ddl_SelectedCauseCodeType")  
            'ddl_SelectedCauseCodeType.Items.Insert(0, New ListItem("-*-", "-1"))  
            'ddl_SelectedCauseCodeType.SelectedValue = -1  
        End If 
    End Sub 
    Protected Sub FormView1_ItemInserted(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted  
        If e.Exception IsNot Nothing Then 
            lbl_SubmissionMsg.Text = "" 
            lbl_ExceptionDetails.Visible = True 
            lbl_ExceptionDetails.Text = String.Concat("The request to insert this batch of kanban defects has encountered an error:  ")  
 
            If e.Exception.InnerException IsNot Nothing Then 
                Dim inner As Exception = e.Exception.InnerException  
                'append the inner exception msg to the main error msg:  
                lbl_ExceptionDetails.Text += inner.Message  
            End If 
            e.ExceptionHandled = True 
        Else 
            lbl_ExceptionDetails.Text = "" 
            lbl_ExceptionDetails.Visible = False 
            lbl_SubmissionMsg.CssClass = "success" 
            lbl_SubmissionMsg.Text = String.Concat("Kanban records were successfully ADDED.")  
 
        End If 
    End Sub 
    Protected Sub lbl_DateEntered_Load(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim lbl_DateEntered As Label = FormView1.FindControl("lbl_DateEntered")  
        'grab current date:  
        lbl_DateEntered.Text = Date.Now  
    End Sub 
    Protected Sub ddl_DeptFoundErr_insert_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        'After selecting a different department:  
        'Object Data Sources:  
        Dim ods_Lseg As ObjectDataSource = FormView1.FindControl("ods_LineSegFoundErr_insert")  
        Dim ods_Op As ObjectDataSource = FormView1.FindControl("ods_OpFoundErr_insert")  
        'Dept Found Error:  
        Dim ddl_DeptFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_DeptFoundErr_insert"), DropDownList)  
        'Line Segment Found Error:  
        Dim ddl_LineSegFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_LineSegFoundErr_insert"), DropDownList)  
        'Operator Found Error:  
        Dim ddl_OpFoundErr As DropDownList = CType(FormView1.Row.FindControl("ddl_OpFoundErr_insert"), DropDownList)  
 
        'get new pdid parameter for LineSeg dropdown:  
        ods_Lseg.SelectParameters(0).DefaultValue = ddl_DeptFoundErr.SelectedValue  
        ddl_LineSegFoundErr.DataBind()  
        'if no linesegments exist for the selected dept found display different message in dropdown:  
        If ddl_LineSegFoundErr.Items.Count = 0 Then 
            ddl_LineSegFoundErr.Items.Insert(0, New ListItem("None Available""-1"))  
        Else 
            ddl_LineSegFoundErr.Items.Insert(0, New ListItem("Select Line Segment""-1"))  
        End If 
 
        'get new pdid parameter for Emp List dropdown:  
        ods_Op.SelectParameters(0).DefaultValue = ddl_DeptFoundErr.SelectedValue  
        ddl_OpFoundErr.DataBind()  
        'listitem(text, value) 'Using -1 for initial value in validation checker instead of empty string  
        ddl_OpFoundErr.Items.Insert(0, New ListItem("Select Operator""-1"))  
        'set value of ddl to the default item "Select an Operator" and display value with label for testing purposes:  
        ddl_OpFoundErr.SelectedValue = -1  
    End Sub 
    Protected Sub ddl_DeptSourceErr_Insert_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim ddl_DeptSourceErr As DropDownList = CType(FormView1.Row.FindControl("ddl_DeptSourceErr_Insert"), DropDownList)  
        Dim ddl_DefectCodes As DropDownList = CType(FormView1.Row.FindControl("ddl_DefectCodes_insert"), DropDownList)  
        Dim ddl_CauseCodeList_insert As DropDownList = FormView1.Row.FindControl("ddl_CauseCodeList_insert")  
 
        'databind the radgrid after dept source is selected:  
        Dim ods_WebSvc_RefList As ObjectDataSource = FormView1.FindControl("ods_WebSvc_RefList")  
        Dim RadGrid_RefCompPtList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RefCompPtList")  
        Dim RadGrid_SelectedRefsList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_SelectedRefsList")  
        RadGrid_RefCompPtList.DataSourceID = "ods_WebSvc_RefList" 
        RadGrid_RefCompPtList.DataBind()  
 
        'Defect Code:  
        ddl_DefectCodes.Items.Clear()  
        ddl_DefectCodes.DataBind()  
        If ddl_DefectCodes.Items.Count = 0 Then 
            ddl_DefectCodes.Items.Insert(0, New ListItem("None Available""-1"))  
            ddl_DefectCodes.SelectedValue = -1  
        Else 
            ddl_DefectCodes.Items.Insert(0, New ListItem("Select Defect Code""-1"))  
            ddl_DefectCodes.SelectedValue = -1  
        End If 
 
        'deselect any selected references (prevents attempt to insert invalid reference for dept source selected):  
        'Clear selected ref arraylist:  
        Clear_RefListArray(sender, e)  
 
        If Not RadGrid_SelectedRefsList Is Nothing Then 
            Dim refDesList_Array As New ArrayList  
            refDesList_Array.Clear()  
            RadGrid_SelectedRefsList.DataSource = refDesList_Array  
            RadGrid_SelectedRefsList.DataBind()  
        End If 
 
        If Not RadGrid_RefCompPtList Is Nothing Then 
            RadGrid_RefCompPtList.DataBind()  
        End If 
 
        'default root cause value:  
        'the default value Y or N is based upon the selected dept source  
        'so when dept source is selected refresh the value.  
        Dim ddl_RCdefault_insert As DropDownList = FormView1.FindControl("ddl_RCdefault_insert")  
        ddl_RCdefault_insert.DataBind()  
 
        'cause codes:  
        ddl_CauseCodeList_insert.Items.Clear()  
        ddl_CauseCodeList_insert.DataBind()  
        If ddl_CauseCodeList_insert.Items.Count = 0 Then 
            ddl_CauseCodeList_insert.Items.Insert(0, New ListItem("No Cause Codes Available for Dept Source""-1"))  
            ddl_CauseCodeList_insert.SelectedValue = -1  
        Else 
            ddl_CauseCodeList_insert.Items.Insert(0, New ListItem("Select Cause Code""-1"))  
            ddl_CauseCodeList_insert.SelectedValue = -1  
        End If 
 
 
 
    End Sub 
    Protected Sub ddl_CauseCodeList_insert_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim ddl_SelectedCauseCodeType As DropDownList = FormView1.FindControl("ddl_SelectedCauseCodeType")  
        Dim ddl_CauseCodeList_insert As DropDownList = FormView1.FindControl("ddl_CauseCodeList_insert")  
        ' ddl_CauseCodeList.DataBind()  
        'ddl_SelectedCauseCodeType.DataBind()  
        'cause code type:  
        'this value isn't submitted to the db it is just for controling the required field property for the Err Orig Station/Operator.  
        'Dim ddl_SelectedCauseCodeType As DropDownList = FormView1.FindControl("ddl_SelectedCauseCodeType")  
        ddl_SelectedCauseCodeType.SelectedValue = ddl_CauseCodeList_insert.SelectedValue  
        ddl_SelectedCauseCodeType.DataBind()  
 
 
    End Sub 
    Protected Sub ods_AddDupDefects_withRC_Inserting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.ObjectDataSourceMethodEventArgs)  
        '#1 KB ID loop thru selected kanban List - pass entire list to insert method in BLL:  
        'Dont need to submit this now that kaban is included in rootcause arraylist.  
        'If Not Session("KBList_Array") Is Nothing Then  
        'kbidList_Array = Session("KBList_Array")  
        ' End If  
        'e.InputParameters.Item("KBList") = kbidList_Array  
 
        '#2 Loop through Array List of Ref Des Codes:  
        If Not Session("RefList_Array"Is Nothing Then 
            refDesList_Array = Session("RefList_Array")  
        End If 
        e.InputParameters.Item("RefDesList") = refDesList_Array  
 
        '3 Loop through ArrayList of RootCause detail rows:  
        If Not Session("RCList_Array"Is Nothing Then 
            rootcauseList_Array = Session("RCList_Array")  
        End If 
        e.InputParameters.Item("RootCauseList") = rootcauseList_Array  
 
 
        'all the other fields are data bound.  
    End Sub 
    Protected Sub ods_AddDupDefects_withRC_Inserted(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs)  
        Dim cnt_RecsAdded As Integer 
        Dim lbl_ResponseMsg As Label = FormView1.Row.FindControl("lbl_ResponseMsg")  
        Dim btn_AddNewDefect As Button = FormView1.FindControl("btn_AddNewDefect")  
 
        'change button text:  
        btn_AddNewDefect.Text = "Insert command completed." 
        btn_AddNewDefect.Enabled = False 
 
        'display number of records inserted:  
        cnt_RecsAdded = e.ReturnValue  
        lbl_ResponseMsg.Text = String.Concat(cnt_RecsAdded.ToString + "  records successfully added.")  
 
    End Sub
#End Region  
 
#Region "ReferenceDesignator Grids" 
    Protected Sub RadGrid_RefCompPtList_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs)  
        Dim RadGrid_RefCompPtList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RefCompPtList")  
        'variables for building and reading arraylist:  
        Dim selected_RefCodeID As New Long 
        Dim selected_RefCodeName As String = "" 
        Dim selected_CompPt As String = "" 
 
        'add selected ref to listbox:  
        If Not RadGrid_RefCompPtList Is Nothing Then 
            selected_RefCodeID = CType(RadGrid_RefCompPtList.SelectedValue.ToString, Long)  
            selected_RefCodeName = Trim(RadGrid_RefCompPtList.SelectedValues.Item("RefDes_Code").ToString)  
            selected_CompPt = Trim(RadGrid_RefCompPtList.SelectedValues.Item("cc_PartNumber").ToString)  
 
            'Add new item to ArrayList (use object to fill in values in new instance of listitme):   
            'set up session variable to hold arraylist object: (otherwise only one item is added to arrylist)  
            If Not Session("RefList_Array"Is Nothing Then 
                refDesList_Array = Session("RefList_Array")  
            End If 
 
            'add new arraylist item to array object and append to session var:  
            refDesList_Array.Add(New objRefDesListItem(selected_RefCodeID, selected_RefCodeName, selected_CompPt))  
 
            'bind ArrayList to GridView:  
            Dim RadGrid_SelectedRefsList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_SelectedRefsList")  
            RadGrid_SelectedRefsList.DataSource = refDesList_Array  
            RadGrid_SelectedRefsList.DataBind()  
 
            'reset session variable to redefind refDesList_Array  
            Session("RefList_Array") = refDesList_Array  
 
        End If 
    End Sub 
    Protected Sub RadGrid_SelectedRefsList_DeleteCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs)  
        Dim RadGrid_SelectedRefsList As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_SelectedRefsList")  
        Dim i As Integer 
        i = e.Item.ItemIndex  
 
        'delete selected row:  
        refDesList_Array = Session("RefList_Array")  
        refDesList_Array.RemoveAt(i)  
 
        'bind ArrayList to GridView:  
        RadGrid_SelectedRefsList.DataSource = refDesList_Array  
        refDesList_Array = Session("RefList_Array")  
        RadGrid_SelectedRefsList.DataBind()  
 
    End Sub
#End Region  
 
#Region "Root Cause RadGrid" 
    Protected Sub RadGrid_RCinsert_NeedDataSource(ByVal source As ObjectByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs)  
        'Bind RootCause Insert radgrid to session var containing selected kbids:  
        Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
        If Not Session("RCList_Array"Is Nothing Then 
            rootcauseList_Array = Session("RCList_Array")  
        End If 
        If Not RadGrid_RCinsert Is Nothing Then 
            If Not rootcauseList_Array Is Nothing Then 
                'this is the old method where I bound the RadGrid to the ArrayList directly.  
                RadGrid_RCinsert.DataSource = rootcauseList_Array  
            End If 
        End If 
    End Sub 
    Protected Sub RadGrid_RCinsert_ItemDataBound(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs)  
        If (TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode) Then 
            Dim item As GridEditableItem = CType(e.Item, GridEditableItem)  
            Dim strKBID As String = item.GetDataKeyValue("KanbanID").ToString  
            kbid_num = CType(strKBID, Long)  
 
            'Display current selected row's KBID for testing purposes:  
            ' Dim RadAjaxManager1 As RadAjaxManager = FormView1.FindControl("RadAjaxManager1")  
            ' RadAjaxManager1.Alert("selected row strKBID:  " + strKBID)  
 
            'set up session variable to hold arraylist object: (otherwise only one item is added to arrylist)  
            If Not Session("RCList_Array"Is Nothing Then 
                rootcauseList_Array = Session("RCList_Array")  
            End If 
 
            'Define RADGridRow's MS DropDownList objects:  
            Dim ddl_RCStationOper_edit As DropDownList = CType(item.FindControl("ddl_RCStationOper_editform"), DropDownList)  
            Dim ddl_MissedByStOper_KBAhistID_edit As DropDownList = CType(item.FindControl("ddl_MissedByStOper_KBAhistID_editform"), DropDownList)  
            Dim ddl_LookBack_edit As DropDownList = CType(item.FindControl("ddl_LookBack_editform"), DropDownList)  
            Dim ddl_InspLookBack_edit As DropDownList = CType(item.FindControl("ddl_InspLookBack_editform"), DropDownList)  
            Dim ddl_InspLookBackMissedByStOper_KBAhistID = CType(item.FindControl("ddl_InspLookBackMissedByStOper_KBAhistID_editform"), DropDownList)  
            Dim ddl_Scrapped_edit As DropDownList = CType(item.FindControl("ddl_Scrapped_editform"), DropDownList)  
 
            'Set current row's Kanban ID to the default select param of ods for ddl root cause oper:  
            Dim ods_KBAssyHistOrigErr_edit As ObjectDataSource = FormView1.FindControl("ods_KBAssyHistOrigErr_edit")  
            If Not ods_KBAssyHistOrigErr_edit Is Nothing Then 
                ods_KBAssyHistOrigErr_edit.SelectParameters("KB_ID").DefaultValue = kbid_num  
                ods_KBAssyHistOrigErr_edit.DataBind()  
            End If 
            ddl_RCStationOper_edit.DataBind()  
            Dim item_count As New Integer 
            item_count = ddl_RCStationOper_edit.Items.Count  
            If item_count = 0 Then 
                ddl_RCStationOper_edit.Items.Clear()  
                ddl_RCStationOper_edit.Items.Insert(0, New ListItem("No Assembly History Recorded for this Kanban""-1"))  
                ddl_RCStationOper_edit.SelectedValue = -1  
                ddl_RCStationOper_edit.DataBind()  
            End If 
 
            'Set current row's Kanban ID to the default select param of ods for ddl missed by oper:  
            Dim ods_MissedByKBAssyHistOrigErr_edit As ObjectDataSource = FormView1.FindControl("ods_MissedByKBAssyHistOrigErr_edit")  
            If Not ods_MissedByKBAssyHistOrigErr_edit Is Nothing Then 
                ods_MissedByKBAssyHistOrigErr_edit.SelectParameters("KB_ID").DefaultValue = kbid_num  
                ods_MissedByKBAssyHistOrigErr_edit.DataBind()  
            End If 
            ddl_MissedByStOper_KBAhistID_edit.DataBind()  
            Dim item_count2 As New Integer 
            item_count2 = ddl_RCStationOper_edit.Items.Count  
            If item_count2 = 0 Then 
                ddl_MissedByStOper_KBAhistID_edit.Items.Clear()  
                ddl_MissedByStOper_KBAhistID_edit.Items.Insert(0, New ListItem("No Assembly History Recorded for this Kanban""-1"))  
                ddl_MissedByStOper_KBAhistID_edit.SelectedValue = -1  
                ddl_MissedByStOper_KBAhistID_edit.DataBind()  
            End If 
 
            'Set current row's Kanban ID to the default select param of ods for ddl Inspection LookBack missed by oper:  
            Dim ods_InspLookBackMissedByKBAssyHistOrigErr_edit As ObjectDataSource = FormView1.FindControl("ods_InspLookBackMissedByKBAssyHistOrigErr_edit")  
            If Not ods_InspLookBackMissedByKBAssyHistOrigErr_edit Is Nothing Then 
                ods_InspLookBackMissedByKBAssyHistOrigErr_edit.SelectParameters("KB_ID").DefaultValue = kbid_num  
                ods_InspLookBackMissedByKBAssyHistOrigErr_edit.DataBind()  
            End If 
            ddl_InspLookBackMissedByStOper_KBAhistID.DataBind()  
            Dim item_count3 As New Integer 
            item_count2 = ddl_RCStationOper_edit.Items.Count  
            If item_count2 = 0 Then 
                ddl_InspLookBackMissedByStOper_KBAhistID.Items.Clear()  
                ddl_InspLookBackMissedByStOper_KBAhistID.Items.Insert(0, New ListItem("No Assembly History Recorded for this Kanban""-1"))  
                ddl_InspLookBackMissedByStOper_KBAhistID.SelectedValue = -1  
                ddl_InspLookBackMissedByStOper_KBAhistID.DataBind()  
            End If 
 
            'reset session variable to redefine kbidList_Array  
            Session("RCList_Array") = rootcauseList_Array  
 
            'Bind RootCause Insert radgrid to session var containing selected kbids:  
            Dim RadGrid_RCinsert As Telerik.Web.UI.RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
            If Not Session("RCList_Array"Is Nothing Then 
                rootcauseList_Array = Session("RCList_Array")  
            End If 
              
        End If 
    End Sub 
    Protected Sub RadGrid_RCinsert_ItemCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs)  
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
        Dim strKBID As String = editedItem.GetDataKeyValue("KanbanID").ToString  
        Dim RadGrid_RCinsert As RadGrid = FormView1.FindControl("RadGrid_RCinsert")  
 
    End Sub 
    Protected Sub RadGrid_RCinsert_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs)  
        Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)  
        Dim strKBID As String = editedItem.GetDataKeyValue("KanbanID").ToString  
 
 
        If (e.CommandName = RadGrid.UpdateCommandName AndAlso e.Item.IsInEditMode = TrueThen 
 
            'For Each editedItem In rootcauseList_Array  
 
            '??? For editedItem As GridEditableItem  
 
            'Display current row's KanbanID for testing purposes:  
            'Dim RadAjaxManager1 As RadAjaxManager = FormView1.FindControl("RadAjaxManager1")  
            'RadAjaxManager1.Alert("selected row strKBID:  " + strKBID)  
 
            'extract values from each dropdownlist in the current selected row in gridcolumns:  
            'set up session vars to hold selected values from MS dropdownlists:  
            Session("sessKanbanID_currRow") = CType(strKBID, Long)  
 
            Dim lbl_KanbanNumber_editform As Label = CType(editedItem.FindControl("lbl_KanbanNumber_editform"), Label)  
            Session("sessKanban_currRow") = lbl_KanbanNumber_editform.Text.ToString  
 
            'ex: CType(editedItem.FindControl(""), DropDownList).SelectedItem.Value  
            'Root Cause Station Operator KBAHist_ID:  
            Dim ddl_RCStationOper_editform As DropDownList = CType(editedItem.FindControl("ddl_RCStationOper_editform"), DropDownList)  
            Dim selected_RCStationOper As String = ddl_RCStationOper_editform.SelectedItem.Value  
            Session("sessRCStationOper_updated") = CType(selected_RCStationOper, Long)  
 
            'LookBack?  
            Dim ddl_LookBack_editform As DropDownList = CType(editedItem.FindControl("ddl_LookBack_editform"), DropDownList)  
            Dim selected_LookBack As String = ddl_LookBack_editform.SelectedValue  
            Session("sessLookBack_updated") = selected_LookBack  
 
            'Missed By Station Operator KBAHist_ID:  
            Dim ddl_MissedByStOper_KBAhistID_editform As DropDownList = CType(editedItem.FindControl("ddl_MissedByStOper_KBAhistID_editform"), DropDownList)  
            Dim selected_MissedByStationOper As String = ddl_MissedByStOper_KBAhistID_editform.SelectedValue  
            Session("sessMissedBy_updated") = CType(selected_MissedByStationOper, Long)  
 
            'Inspector LookBack MissedBy:  
            Dim ddl_InspLookBackMissedByStOper_KBAhistID_editform As DropDownList = CType(editedItem.FindControl("ddl_InspLookBackMissedByStOper_KBAhistID_editform"), DropDownList)  
            Dim selected_InspLBMissedBy As String = ddl_InspLookBackMissedByStOper_KBAhistID_editform.SelectedValue  
            Session("sessInspectionLookBackMissedBy_updated") = selected_InspLBMissedBy  
 
            'Scrapped?  
            Dim ddl_Scrapped_editform As DropDownList = CType(editedItem.FindControl("ddl_Scrapped_editform"), DropDownList)  
            Dim selected_Scrapped As String = ddl_Scrapped_editform.SelectedValue  
            Session("sessScrapped_updated") = selected_Scrapped  
 
            'RootCause Operator Name:  
            Dim selected_RCStationOperName As String = ddl_RCStationOper_editform.SelectedItem.Text  
            Session("sessRCStationOperName_updated") = selected_RCStationOperName  
 
            'Missed By Name:  
            Dim selected_MissedByStationOperName As String = ddl_MissedByStOper_KBAhistID_editform.SelectedItem.Text  
            Session("sessMissedByName_updated") = selected_MissedByStationOperName  
 
            'Inspection LB Name:  
            Dim selected_InspLBMissedByStationOperName As String = ddl_InspLookBackMissedByStOper_KBAhistID_editform.SelectedItem.Text  
            Session("sessInspLBMissedByName_updated") = selected_InspLBMissedByStationOperName  
 
            'variables to populate arraylist object:  
            Dim KanbanID As Long 
            Dim Kanban As String 
            Dim RootCause_StOper As Long 
            Dim LookBack As String 
            Dim MissedBy_StOper As Long 
            Dim InspectionLBMissedBy_StOper As Long 
            Dim Scrapped As String 
            Dim RootCause_StOper_Name As String 
            Dim MissedBy_StOper_Name As String 
            Dim InspectionLBMissedBy_StOper_Name As String 
 
            KanbanID = Session("sessKanbanID_currRow")  
            Kanban = Session("sessKanban_currRow")  
            RootCause_StOper = Session("sessRCStationOper_updated")  
            LookBack = Session("sessLookBack_updated")  
            MissedBy_StOper = Session("sessMissedBy_updated")  
            InspectionLBMissedBy_StOper = Session("sessInspectionLookBackMissedBy_updated")  
            Scrapped = Session("sessScrapped_updated")  
            RootCause_StOper_Name = Session("sessRCStationOperName_updated")  
            MissedBy_StOper_Name = Session("sessMissedByName_updated")  
            InspectionLBMissedBy_StOper_Name = Session("sessInspLBMissedByName_updated")  
 
            rootcauseList_Array.Add(New objDefectRootCauseRec( _  
                                                      KanbanID, _  
                                                      Kanban, _  
                                                      RootCause_StOper, _  
                                                      LookBack, _  
                                                      MissedBy_StOper, _  
                                                      InspectionLBMissedBy_StOper, _  
                                                      Scrapped, _  
                                                      RootCause_StOper_Name, _  
                                                      MissedBy_StOper_Name, _  
                                                      InspectionLBMissedBy_StOper_Name))  
 
            '???  Next  
 
            'reset session variable to redefine kbidList_Array  
            Session("RCList_Array") = rootcauseList_Array  
            ''only one itm in array now!!!!!!!!!!  
 
 
            'clear session vars for selected row:  
            ClearSessionVars_currRow()  
 
        End If 
 
    End Sub
#End Region  
 
    Protected Sub RadGrid_RCinsert_ItemUpdated(ByVal source As ObjectByVal e As Telerik.Web.UI.GridUpdatedEventArgs)  
 
    End Sub 
End Class 
 



0
Tsvetoslav
Telerik team
answered on 30 Jan 2009, 09:49 AM
Hi JW,

You can review the following examples and documentation on radgrid's automatic operations with object data source:

- Automatic Operations with ObjectDataSrouce
- Automatic DataSource Operations
- Custom paging...using ObjectDataSource 

If this doesn't help, you can send a complete running application (along with any user controls, master pages and a database) through a formal support ticket.

Regards,
Tsvetoslav
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
JW
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
JW
Top achievements
Rank 1
Share this question
or