_XHTML/WEB_黑客防线网安服务器维护基地--Powered by WWW.RONGSEN.COM.CN

xml教程:GridViewRow可以任意位置单击引发事件的方法

作者:黑客防线网安XML教程基地 来源:黑客防线网安XML教程基地 浏览次数:0

本篇关键词:引发事件方法位置

  GridView 是 ASP.NET 2.0 中应用最为广泛一个控件几乎所有的数据操作都需要它正如我们平常所应用的,可以编辑、删除、选择等等,但如果客户有需要通过单击行而引发超链接或者进入行编辑状态时,我们该如何实现,这里介绍了一种方法来实现此功能它将允许你通过点击行的任何一个位置而引发你所需要的事件

  首先为 GridView 填充数据

  private void BindData()
  {
  SqlConnection myConnection = new SqlConnection(ConnectionString);
  SqlCommand myCommand = new SqlCommand("SELECT * FROM Users", myConnection);
  SqlDataAdapter ad = new SqlDataAdapter(myCommand);
  DataSet ds = new DataSet();
  ad.Fill(ds);
  GridView1.DataSource = ds;
  GridView1.DataBind();
  }
 接下来我们在 GridView_RowDataBound 事件中为 GridViewRow 赋予单击属性

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  string alertBox = "alert('";
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  alertBox += e.Row.RowIndex;
  alertBox += "')";
  e.Row.Attributes.Add("onclick", alertBox);
  }
  }

 好了,很简单的方法,希望对你有用!

    黑客防线网安服务器维护方案本篇连接:http://shop.rongsen.com.cn/show-16146-1.html
网站维护教程更新时间:2012-04-06 01:08:31  【打印此页】  【关闭
我要申请本站N点 | 黑客防线官网 |  
专业服务器维护及网站维护手工安全搭建环境,网站安全加固服务。黑客防线网安服务器维护基地招商进行中!QQ:29769479

footer  footer  footer  footer