How do I select a complete dataGridView Row when the user clicks a cell of that row?

后端 未结 6 1011
梦毁少年i
梦毁少年i 2020-12-14 14:01

I have a dataGridView and I need that when the user clicks on any cell the whole row that contains this cell is selected too. (it has multiselect disbaled) I t

6条回答
  •  悲哀的现实
    2020-12-14 14:45

    Could do something like this

    protected override void Render(HtmlTextWriter writer)
    {
        foreach (GridViewRow row in Results.Rows)
        {
            if (row.RowType == DataControlRowType.DataRow)
            {
                row.Attributes["onmouseover"] = "this.style.cursor='pointer';";
                row.CssClass = "rowHover";
                row.ToolTip = "Click row to view person's history";
                row.Attributes.Add("onclick", this.ClientScript.GetPostBackClientHyperlink(this.Results,"Select$" & r.RowIndex , true));
            }
        }
    
        base.Render(writer);
    }
    

提交回复
热议问题