CopyPastor

Detecting plagiarism made easy.

Score: 0.7501137256622314; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2018-07-26
by Gauravsa

Original Post

Original - Posted on 2013-03-27
by alejandrobog



            
Present in both answers; Present only in the new answer; Present only in the old answer;

You can highlight a Row in **GridView** by using the `onmouseover` event. The following code will color the **GridView** row while mouse hovering.
if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onmouseover"] = "this.style.backgroundColor='aquamarine';"; e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='white';"; }
The resulting code is below: You can also get the selected Gridview cell value using `OnSelectedIndexChanged` event:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Attributes["onmouseover"] = "this.style.backgroundColor='aquamarine';"; e.Row.Attributes["onmouseout"] = "this.style.backgroundColor='white';"; e.Row.ToolTip = "Click last column for selecting this row."; } } protected void OnSelectedIndexChanged(object sender, EventArgs e) { string pName = GridView1.SelectedRow.Cells[1].Text; msg.Text = "<b>Publisher Name &nbsp;:&nbsp;&nbsp; " + pName + "</b>"; }
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); }

        
Present in both answers; Present only in the new answer; Present only in the old answer;