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

Can't be call codebehind when use GridEditCommandColumn

1 Answer 95 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Thitikorn Wachiraarunwong
Top achievements
Rank 1
Thitikorn Wachiraarunwong asked on 14 Sep 2008, 05:50 PM

i use gridview for show data and last time i need to edit some detail by tag GridEditCommandColumn in telerik function .. i found problem to use update
in grid because it can't be call codebehind ( event  grdSearchDetailKeywords_UpdateCommand ) this below is my code  design

---------------------------------------------------------------------

 <radG:RadGrid
                                ID="grdSearchDetailKeywords"
                                AutoGenerateColumns ="false"
                                runat="server"
                                ShowStatusBar="false"
                                GridLines="None"
                                Width="100%"
                                UseEmbeddedScripts="false"
                                AllowAutomaticUpdates="True"
                                AllowMultiRowSelection="True"
                                AllowMultiRowEdit="True"
                                AllowPaging ="true"
                                PageSize ="5"
                                Skin="Default2006"
                                Visible ="false">
                                <PagerStyle
                                    NextPageText="Next"
                                    PrevPageText="Prev">
                                </PagerStyle>
                                <ClientSettings Selecting-AllowRowSelect="true" />
                                       <MasterTableView
                                        AutoGenerateColumns="False"
                                        DataKeyNames="Search ID"
                                        CommandItemDisplay="Top"
                                        EditMode="InPlace">
                                            <CommandItemTemplate>
                                            <asp:LinkButton
                                                ID="lbtDeleteSearchName"
                                                CausesValidation="False"
                                                OnClientClick="if(!confirm('Would you like to delete selected keywords?'))return false;"
                                                Runat="server"
                                                OnClick ="lbtDeleteSearchName_Click">
                                                <asp:Image
                                                    ID="imgDeleteSearchKeyword"
                                                    Runat="server"
                                                    ImageUrl="~/Images/delete.gif" />
                                            </asp:LinkButton>
                                            </CommandItemTemplate>
                                            <Columns>                                           
                                                <radG:GridTemplateColumn>
                                                    <ItemTemplate>
                                                        <asp:CheckBox
                                                            ID="chkSelectedDeleteDetailSearch"
                                                            Runat="Server" />
                                                    </ItemTemplate>
                                                </radG:GridTemplateColumn>
                                                <radG:GridTemplateColumn>
                                                    <ItemTemplate >
                                                        <asp:Label
                                                            ID="lblSearchID"
                                                            runat="server"
                                                            Visible="false"
                                                            Text='<%#Bind("[Search ID]") %>' />
                                                        <asp:ImageButton
                                                            id="ibtViewSearchedDetail"
                                                            runat="Server"
                                                            ImageUrl="Images/ViewRecord.jpg"
                                                            OnClick="ibtViewSearchedDetail_Click"
                                                            Width="15px"
                                                            Height="15px"/>
                                                    </ItemTemplate>
                                                </radG:GridTemplateColumn>
                                                <radG:GridEditCommandColumn
                                                    ButtonType="ImageButton"
                                                    UpdateText="Update"
                                                    UniqueName="EditCommandColumn"
                                                    CancelText="Cancel"
                                                    EditText="Edit">
                                                    <HeaderStyle Width="15px" ></HeaderStyle>
                                                </radG:GridEditCommandColumn>
                                                <radG:GridBoundColumn
                                                    DataField ="Search ID"
                                                    HeaderText ="Search ID"
                                                    UniqueName="Search ID"
                                                    Visible= "false">
                                               
                                                </radG:GridBoundColumn>
                                                <radG:GridBoundColumn
                                                    DataField ="Search Name"
                                                    HeaderText ="Search Name"
                                                    UniqueName="Search Name" >
                                               
                                                </radG:GridBoundColumn>
                                               
                                             
                                            </Columns>
                                        </MasterTableView>
                            </radG:RadGrid>

------------------------------------------------------------------------

and this is sub of updatecommand

------------------------------------------------------------------------

 Protected Sub grdSearchDetailKeywords_UpdateCommand( _
        ByVal source As Object, _
        ByVal e As Telerik.WebControls.GridCommandEventArgs) _
    Handles grdSearchDetailKeywords.UpdateCommand
        ' ***   Created on 08-29-2008.                                                                  ***
        ' ***   Last updated on 08-29-2008.                                                             ***
        ' ***   Created by Thitikorn Wachiraarunwong.                                                   ***
        ' ***   Last updated by  Thitikorn Wachiraarunwong .                                            ***
        Try

            strUserName = Session("UserName")
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim editMan As GridEditManager = editedItem.EditManager
            Dim column As GridColumn


            For Each column In e.Item.OwnerTableView.Columns
                If TypeOf column Is IGridEditableColumn Then
                    Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
                    If (editableCol.IsEditable) Then
                        Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
                        Dim editorType As String = CType(editor, Object).ToString()
                        Dim editorText As String = "unknown"
                        Dim editorValue As Object = Nothing
                        Dim editorID As Integer = 0

                        If (TypeOf editor Is GridTextColumnEditor) Then
                            editorText = CType(editor, GridTextColumnEditor).Text
                            'editorValue = CType(editor, GridTextColumnEditor).Text
                            editorID = editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("Search ID")
                            If editorText <> "" And editorID <> 0 Then
                                ccoGetData.fnManageSearches _
                                    ( _
                                        editorID, _
                                        "Update", _
                                        editorText, _
                                        strUserName _
                                    )


                                ' ***   Get String in text for searching again and Set in Datatable                         ***
                                dtbDetails = ccoGetData.fnGetSearches()
                                strSearchDetail = "[Search Name] LIKE " & "'%" & txtSearchName.Text & "%'"
                                drwDetailSearch = dtbDetails.Select(strSearchDetail)
                                dtbSetSearchKeyword = dtbDetails.Clone()

                                For Each drwIndex As DataRow In drwDetailSearch
                                    dtbSetSearchKeyword.Rows.Add(drwIndex.ItemArray)
                                Next

                                Session("Seach Detail Keywords") = dtbSetSearchKeyword
                                'grdSearchDetailKeywords.Rebind()

                                'grdSearchDetailKeywords.MasterTableView.Items(0).Edit = False
                                grdSearchDetailKeywords.MasterTableView.ClearChildEditItems()
                                grdSearchDetailKeywords.MasterTableView.Rebind()

                            End If
                        End If
                    End If
                End If
            Next
        Catch
            Session("Error") = True
            strErrorDescription = Replace(Err.Description, """", "'")
            strErrorNumber = Err.Number
            strLocation = "Detail Search  "
            strModule = "Update Search Detail Keyword"
            strStatusMessage = ccoUtilities.fnErrorHandler _
                ( _
                    strErrorDescription, _
                    strErrorNumber, _
                    strLocation, _
                    strModule _
                )
            ScriptManager.RegisterStartupScript(Me.Page, Me.GetType(), "ErrorMessage", _
                "radalert(""" & strStatusMessage & """, 330, 210);", True)
        End Try

    End Sub

-------------------------------------------------------------------------


i need to know why i can't call codebehind from this code

thank you for help .

1 Answer, 1 is accepted

Sort by
0
Vladimir
Top achievements
Rank 1
answered on 15 Sep 2008, 04:18 AM
How the grid is bound in your case? You need to use advanced data-binding with NeedDataSource.
Tags
Grid
Asked by
Thitikorn Wachiraarunwong
Top achievements
Rank 1
Answers by
Vladimir
Top achievements
Rank 1
Share this question
or