Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: ASP
Posted by: Mario Lopes
Added: Dec 2, 2019 6:53 PM
Modified: Dec 3, 2019 11:37 AM
Views: 9
  1. protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  2.     {        
  3.         Response.Write(GridView1.SelectedRow.Cells[0].Text);
  4.     }
  5.     protected override void Render(HtmlTextWriter writer)
  6.     {
  7.         foreach (GridViewRow r in GridView1.Rows)
  8.         {
  9.             if (r.RowType == DataControlRowType.DataRow)
  10.             {
  11.                 r.Attributes["onmouseover"] = "this.style.cursor='pointer';";
  12.                 r.Attributes["onmouseout"] = "this.style.textDecoration='none';";
  13.                 r.ToolTip = "Clique para selecionar";
  14.                 r.Attributes["onclick"] = this.Page.ClientScript.GetPostBackClientHyperlink(this.GridView1, "Select$" + r.RowIndex, true);
  15.  
  16.             }
  17.         }
  18.  
  19.         base.Render(writer);
  20.     }
  21.  
  22. Então fazer (usando datakeys)
  23. protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  24.     {
  25.         Response.Write(GridView1.DataKeys[GridView1.SelectedIndex]["id"].ToString());      
  26.     }
  27.  
  28.