How to implement full row selecting in GridView without select button?

前端 未结 5 1203
深忆病人
深忆病人 2020-11-27 04:33

I\'m implementing a feature that when the user press on any point in the row in a GridView the row will be selected instead of Select button.

5条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 05:26

    Instead of doing it on RowCreated, you could do it on Render(). That way you could use the overload of GetPostBackClientHyperlink with true on registerForEventValidation and avoid the "invalid postback/callback argument" error.

    Something like this:

    protected override void Render(HtmlTextWriter writer)
        {
          foreach (GridViewRow r in GridView1.Rows)
          {
            if (r.RowType == DataControlRowType.DataRow)
            {
              r.Attributes["onmouseover"] = "this.style.cursor='pointer';this.style.textDecoration='underline';";
              r.Attributes["onmouseout"] = "this.style.textDecoration='none';";
              r.ToolTip = "Click to select row";
              r.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + r.RowIndex,true);
    
            }
          }
    
          base.Render(writer);
        }
    

提交回复
热议问题