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)
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 |
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: |
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? |
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: |
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: |
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? |
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 Object, ByVal 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 Object, ByVal 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 Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) | |
End Sub | |
Protected Sub RadGrid_RCinsert_ItemCommand(ByVal source As Object, ByVal 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 |