Custom GridView delete button

后端 未结 3 866
挽巷
挽巷 2021-01-25 07:47

How can I customize automatically generated command button, e.g. Delete?

I want to add a client confirmation on deleting and in the same moment I want this

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-25 08:11

    I would rather recommend using the RowDataBound-event instead of the PreRender-event.

    There you can easily have access to your Elements in the specific row. (I think the solution Kelsey posted might have problems with paging (maybe just combined with ajax))

    Give the Linkbutton an ID and subsribe to the RowDataBound-event.

      void gv_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
        if(e.Row.RowType == DataControlRowType.DataRow)
        {
          LinkButton _foo = e.Row.FindControl("LINKBUTTONID") as LinkButton;
          if(_foo != null)
          {
           _foo.OnClientClick = "insert localized text here";
          }
        }
      }
    

提交回复
热议问题