GridView 行点击事件

//1.xml

 

 

<?xml version="1.0" encoding="utf-8" ?>

<studentbook>

  <student>

    <sno>1</sno>

    <sname>liu</sname>

    <sgrade>88</sgrade>

  </student>

  <student>

    <sno>2</sno>

    <sname>liu2</sname>

    <sgrade>882</sgrade>

  </student>

  <student>

    <sno>3</sno>

    <sname>liu3</sname>

    <sgrade>883</sgrade>

  </student>

</studentbook>

 

 



//default.aspx

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;


namespace WebApplication1

{

    public partial class _default : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            this.GridView1.DataSource = CreateDataSource();

            this.GridView1.DataBind();

        }


        private DataSet CreateDataSource()

        {

            DataSet ds = new DataSet("xmlds");

            ds.ReadXml(Server.MapPath("~\\1.xml"));

            return ds;

        }


        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

        {

            if (e.Row.RowType == DataControlRowType.DataRow)

            {

                if (e.Row.RowIndex % 2 == 0)

                {

                    e.Row.Attributes.Add("onmouseover", "this.style.cursor='hand';this.style.background='#ccc'");

                }

                else

                {

                    e.Row.Attributes.Add("onmouseover", "this.style.background='white'");

                }

                int b = Convert.ToInt32(e.Row.Cells[2].Text);

                e.Row.Attributes.Add("onclick", string.Format("location.href='{0}'","Test.aspx?aa="+b+""));

            }

        }

    }

}

//Test.aspx

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;


namespace WebApplication1

{

    public partial class Test : System.Web.UI.Page

    {

        protected void Page_Load(object sender, EventArgs e)

        {

            if (!IsPostBack)

            {

                TextBox1.Text=Request.QueryString["aa"];

            }

        }

    }

}


 

 

posted @ 2008-11-20 10:03  做你所想  阅读(574)  评论(0编辑  收藏  举报