Friday 22 March 2013

how to create onclick,onmouse over,onmouseout event from code behind page in asp.net



Description:-

                  in this example we explain that how to create  onclick,onmouseover,onmousemove or other event   in Gridview Row at runtime or in CodeBehind Class.

When user is Move Mouse on Each Row of GridView you Can Perform Anything or Display Detail of Each Row in a ModalPopup.same thing you will perform with Onclick or OnMouseOver Event. This is  a one kind of facility or you can change the Color of the Row when Mouse is Clicked on each Row.

use of this example are as follws:-

  1. you can perform the onclick event in each row of gridview and you can change the color of row that are clicked or selected.
  1. you can perform the onmouse over method and its Detail are display in popup window
  2. you can also send the ID of each row to the next page when row is clicked.




Example:-


protected void GridView1_RowDataBound(GridViewRowEventArgs e)
    {
        e.Row.Attributes.Add("onclick", "OpenNewPage('" + e.Row.RowIndex + "')");
    }

or


    protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            System.Data.DataRowView drv = e.Row.DataItem as System.Data.DataRowView;
            e.Row.Attributes.Add("ondblclick", String.Format("window.location='Default7.aspx?id={0}'", drv["id"]));
        }

    }




0 comments:

Post a Comment