Gridview RowUpdating event does not fire

I have a gridview with AutoGenerateColumns="False".
I use TemplateField to display my Edit, Update, and Cancel buttons in the first GridView column in the corresponding ItemTemplate and EditItemTemplate fields.

Inside the ItemTemplate, I have an ImageButtong with CommandName "Edit". This works as expected, and I can set a breakpoint in the RowCommand event handler to see the name of the Event command. After it has been pressed, postback puts this line into edit mode. All text fields are displayed as they are intended.

At this point, the above EditItemTemplate is displayed with two ImageButtons inside it. He has CommandName = "Update", and the other is Cancel.

My problem is that clicking on the Update ImageButton is sent back, but the RowCommand and RowUpdating events are not triggered.

I set the required attributes in the GridView tag. (Note that in gridview EnableViewState="False"- if I set it to True, I get the standard

"Failed to load image in view. Control tree ..." etc.)

One strange thing I noticed makes me think that the ViewState problem is that if I changed the CommandName button of the Update button to “Edit”, then the postback event will be captured in the RowCommand event ...

Any suggestions are welcome. Thanks.

+3
source share
10 answers

, GridView , . - ( - MS) , .

+1

Asem Ron, CausesValidation = "false" CommandField . , GridView , , ValidationSummary.

+7

, "" ( ) .

CausesValidation="false", . , , AutoGenerateEditButton="True" gridview.

, , .

  • AutoGenerateEditButton="False" , ASP.

  • , "" gridView, .

    <asp:commandfield showeditbutton="true" causesvalidation="false" headertext="Edit"/> 
    

, , , .

+4

,

, , addhandler , , . . , .

// pageload

If Not IsPostBack Then
        'Create new column for Edit buttons
        'Dim field As New TemplateField
        Dim actionfield As New TemplateField


        actionfield.HeaderText = "Action"
        Dim actioncol As DataControlField = actionfield
        GridView1.Columns.Insert(8, actioncol)//the eight is the column number of where you are adding the column. below you will add the button. You really don't need to add this column programmtically. I normally do though.

    End If

//rowcreated

 If e.Row.RowType <> DataControlRowType.footer Then
            btnedit.ToolTip = "Edits the Current Record"
            btnedit.ImageUrl = "\images\bttnEditMini.gif"
            GridView1.Rows(i).Cells(8).Controls.Add(btnedit)
            btnedit.CommandName = "view"//notice commandname. You can manipulate it.
            btnedit.CommandArgument = GridView1.Rows(i).Cells(0).Text
            AddHandler btnedit.Click, AddressOf btnedit_Click
 end if

// , imageclickeventhandler

 Public Delegate Sub ImageClickEventHandler(ByVal sender As Object, ByVal e As ImageClickEventArgs)
Sub btnedit_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
//whatever actions you need to take.   

end sub
+1

:

   If Not Master.Page.IsPostBackEventControlRegistered Then

        'logic to bind data

   End If
+1

GridView EnableViewState true.

+1

"update", , - ?

, .


-, , , , Rowcommand. / .

0

Gridview Edit, update, cancel. , . , , CauseValidation false " " " ". .

0

, . , , - . , , CasuesValidation false... , , , .

  • , gridview, page_load.
  • 'CausesValidation' ( , ), , , , .
  • Profit.
0
source

If you use any function to retrieve (bind) the grid view from the database and call it in the page_Load () event , this may cause this problem. try calling this function in the page_LoadComplete () event and it will work.

0
source

Source: https://habr.com/ru/post/1710023/


All Articles