What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 874 |  Welcome, Guest!   Register  Login
 Home > Forums > ASP.NET 4.0 > Row double click event for gridview ...
Bravi

Row double click event for gridview

Replies: 3 | Posted by: Bravi on 1/11/2011 | Category: ASP.NET 4.0 Forums | Views: 10831 | Status: [Member] | Points: 10  


In girdview if we double click on a particular row i need to open an other window
and select a one row and click on open button we have show new window.


Reply | Reply with attachment | Alert Moderator

 Responses below this adGet hundreds of .NET Tips and Tricks videos

 Replies

Karthikanbarasan
Karthikanbarasan  
Posted on: 1/12/2011 12:19:25 AM
Level: Silver | Status: [Member] [Moderator] [Microsoft_MVP] [MVP] | Points: 25

Hi!

Use the below code... it takes the values from cells and pass as query string to the new window and u need to make use of the query string as

Request.QueryString["columnname"]



<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);
}
}


Let me know if any questions

Thanks
Karthik
www.f5Debug.net

Bravi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Bravi
Bravi  
Posted on: 1/12/2011 9:52:46 AM
Level: Starter | Status: [Member] | Points: 25

Thanks Karthik. This is working. There are few other things that I need for the grid, please find the details below:

1. When the user click on a row the gridview row should get selected / highlighted (by changing the background color) and the selected index should get updated.

2. When the user double clicks on a row the selected row should get highlighted by changing its background color.

Bravi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Karthikanbarasan
Karthikanbarasan  
Posted on: 1/12/2011 12:13:28 PM
Level: Silver | Status: [Member] [Moderator] [Microsoft_MVP] [MVP] | Points: 25

Hi Bravi,

See the code below...

Following javascript will be used to change the color of the row.

<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>


Following code will be required on GridView1_RowDataBound event

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


Thanks
Karthik
www.f5Debug.net

Bravi, if this helps please login to Mark As Answer. | Reply | Alert Moderator 

Reply - Please login to reply


Click here to login & reply

Found interesting? Add this to:


 Latest Posts

Write New Post | More ...

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/25/2013 6:27:52 PM