I having the problem for edit / insert. The edit form still showing after click on update/ insert button. But, the data can insert to the database.
| <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server"> |
| <script type="text/javascript"> |
| function RowDblClick(sender, eventArgs) { |
| sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical()); |
| } |
| </script> |
| </telerik:RadCodeBlock> |
| <telerik:RadGrid ID="gNew" GridLines="None" runat="server" AllowAutomaticDeletes="True" |
| AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" AllowPaging="True" |
| AutoGenerateColumns="False"> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <MasterTableView Width="100%" CommandItemDisplay="TopAndBottom" DataKeyNames="pollAnswerID" HorizontalAlign="NotSet" AutoGenerateColumns="False"> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn"> |
| <ItemStyle CssClass="MyImageButton"/> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridBoundColumn DataField="pollAnswer_text" HeaderText="Answer" SortExpression="pollAnswer_text" |
| UniqueName="pollAnswer_text" ColumnEditorID="GridTextBoxColumnEditor1"> |
| </telerik:GridBoundColumn> |
| <telerik:GridButtonColumn ConfirmText="Delete this answer?" ConfirmDialogType="RadWindow" |
| ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" |
| UniqueName="DeleteColumn"> |
| <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| <EditFormSettings EditFormType="Template"> |
| <FormTemplate> |
| <table border="0" cellpadding="5" cellspacing="0" style="padding:10px; background-color:#FDEFBB;" width="100%"> |
| <tr> |
| <td> |
| <b>Answer </b> |
| </td> |
| <td> |
| <asp:TextBox ID="tAnswer" runat="server" Width="400px" Text='<%# Bind( "pollAnswer_text" ) %>'> </asp:TextBox> |
| <asp:RequiredFieldValidator ID="RFVtAnswer" Display="Dynamic" Text="Please enter the answer." runat="server" Font-Bold="true" |
| ControlToValidate="tAnswer" >Please enter the answer.</asp:RequiredFieldValidator> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| </td> |
| <td> |
| <asp:Button ID="btnUpdate" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update Answer") %>' |
| runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'> |
| </asp:Button> |
| <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" |
| CommandName="Cancel"></asp:Button> |
| </td> |
| </tr> |
| </table> |
| </FormTemplate> |
| </EditFormSettings> |
| </MasterTableView> |
| <ClientSettings> |
| <ClientEvents OnRowDblClick="RowDblClick" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| <telerik:GridTextBoxColumnEditor ID="GridTextBoxColumnEditor1" runat="server" TextBoxStyle-Width="400px" /> |
| Protected Sub gNew_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles gNew.NeedDataSource |
| Dim mClas As ExodusG2.dbOps = New ExodusG2.dbOps |
| Dim dt As DataTable = New DataTable |
| Dim alin As ArrayList = New ArrayList |
| Dim alout As ArrayList = New ArrayList |
| Dim sSql As String |
| sSql = "SELECT Polls.pollID, PollAnswers.pollAnswer_text, PollAnswers.pollAnswer_order, PollAnswers.pollAnswer_status, PollAnswers.pollAnswerID FROM Polls INNER JOIN PollAnswers ON Polls.pollID = PollAnswers.pollID where PollAnswers.pollID ='" & Request.QueryString("ID") & "' and pollAnswer_status=1" |
| dt = mClas.GetDataTable(sSql) |
| gNew.DataSource = dt |
| End Sub |
| Protected Sub gNew_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gNew.ItemCommand |
| Dim mClas As ExodusG2.dbOps = New ExodusG2.dbOps |
| Dim AlIn As ArrayList = New ArrayList |
| Dim ssql As String |
| If e.CommandName = RadGrid.InitInsertCommandName Then '"Add new" button clicked |
| Dim editColumn As GridEditCommandColumn = CType(gNew.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn) |
| editColumn.Visible = False |
| ElseIf (e.CommandName = RadGrid.RebindGridCommandName AndAlso e.Item.OwnerTableView.IsItemInserted) Then |
| e.Canceled = True |
| Else |
| Dim editColumn As GridEditCommandColumn = CType(gNew.MasterTableView.GetColumn("EditCommandColumn"), GridEditCommandColumn) |
| If Not editColumn.Visible Then |
| editColumn.Visible = True |
| End If |
| End If |
| If e.CommandName = "Delete" Then |
| 'Get the GridDataItem of the RadGrid |
| Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
| 'Get the primary key value using the DataKeyValue. |
| Dim answerID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("pollAnswerID").ToString() |
| AlIn.Clear() |
| AlIn.Add("2") |
| AlIn.Add(answerID) |
| mClas.execute_query("update PollAnswers set pollAnswer_status=@param1 WHERE pollAnswerID=@param2", AlIn) |
| End If |
| If e.CommandName = "Update" Then |
| Dim edititem As GridEditableItem = TryCast(e.Item, GridEditableItem) |
| Dim answerID As String = edititem.OwnerTableView.DataKeyValues(edititem.ItemIndex)("pollAnswerID").ToString() |
| AlIn.Clear() |
| AlIn.Add(CType(e.Item.FindControl("tAnswer"), TextBox).Text) |
| AlIn.Add(answerID) |
| mClas.execute_query("update PollAnswers set pollAnswer_text=@param1 WHERE pollAnswerID=@param2", AlIn) |
| End If |
| If e.CommandName = "PerformInsert" Then |
| Dim insertItem As GridEditFormInsertItem = DirectCast(e.Item, GridEditFormInsertItem) |
| Dim Guid As String = System.Guid.NewGuid().ToString |
| ssql = "Insert into PollAnswers (pollAnswerID,pollID,pollAnswer_text,pollAnswer_order,pollAnswer_status) Values (@param1,@param2,@param3,@param4,@param5)" |
| AlIn.Clear() |
| AlIn.Add(System.Guid.NewGuid().ToString) |
| AlIn.Add(Request.QueryString("ID")) |
| AlIn.Add(CType(e.Item.FindControl("tAnswer"), TextBox).Text) |
| AlIn.Add("1") |
| AlIn.Add("1") |
| mClas.execute_query(ssql, AlIn) |
| End If |
| End Sub |