<script type="text/javascript"> function popItUp(querystring) { window.open('mywindow.aspx' + querystring); } </script> <asp:GridView id="gv" runat="server" OnRowDataBound="gv_RowDataBound"> ... </asp:GridView> void gv_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string queryString = string.Empty; for (int x = 0; x < gv.Columns.Count; x++) { string separator = (x == 0 ? "?" : "&"); queryString += string.Format("{0}{1}={2}", separator, gv.Columns[x].HeaderText, e.Row.Cells[x].Text); } e.Row.Attributes["ondblclick"] = string.Format("popItUp({0})", queryString); } }
Thanks Karthik www.f5Debug.net
<script type="text/javascript"> //variable that will store the id of the last clicked row var previousRow; function ChangeRowColor(row) { //If last clicked row and the current clicked row are same if (previousRow == row) return;//do nothing //If there is row clicked earlier else if (previousRow != null) //change the color of the previous row back to white document.getElementById(previousRow).style.backgroundColor = "#ffffff"; //change the color of the current row to light yellow document.getElementById(row).style.backgroundColor = "#ffffda"; //assign the current row id to the previous row id //for next row to be clicked previousRow = row; } </script>
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _ Handles GridView1.RowDataBound If (e.Row.RowType = DataControlRowType.DataRow) Then e.Row.Attributes.Add("onclick", "javascript:ChangeRowColor('" & e.Row.ClientID & "')") End If End Sub Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then 'FillDataTable is a function that will return a DataTable 'with some values and is available in the code for download. Me.GridView1.DataSource = Me.FillDataTable() Me.GridView1.DataBind() End If End Sub
Login to post response