问题1
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {
         
        }  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{}上面哪一个才是行单击事件。问题2
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    e.Row.Attributes.Add("onclick", "alert('" +GridView1.Rows[0].Cells[0].text.ToString()+ "');");
}
为什么这个报索引越界

解决方案 »

  1.   

    1。前提是你点了有select command的列。2。e.Row.Attributes.Add("onclick", "alert('" +e.Cells[0].T
    ext.ToString()+ "');");
      

  2.   

    前提是你点了有select command的列  这句上面意思。
    我估计这就是问题的关键
      

  3.   

    为什么这个报索引越界??
    因为在RowDataBound事件中,是一行一行绑定数据,形成 GridView的数据,
    你在还没绑定完数据,就调用GridView1.Rows[0],就会报错的!!
    照你的想法,程序应该是这样:
        string n = "";
        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowIndex == 0)
                    n = e.Row.Cells[0].Text;            e.Row.Attributes.Add("onclick", "alert('" + n + "');");        }
        }
      

  4.   

    e.Row.Attributes.Add("onclick", "alert('" +GridView1.Rows[0].Cells[0].text.ToString()+ "');");======红色的绑定问题。
      

  5.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
          if (e.Row.RowType == DataControlRowType.DataRow)
         {
              e.Row.Attributes.Add("onclick", "A('" +e.Cells[0].text.ToString()+ "');");");
        }
        }单击行执行A()
    列是否存在
      

  6.   

    Gridview控件15种用法大总结
    本篇文章来源于 http://www.17aspx.com 
    原文链接:http://www.17aspx.com/html/aspnet/controls/2009/0920/60.html