日期:2014-05-20  浏览次数:20478 次

关于调用GridView1_SelectedIndexChanging下代码的问题??
我做了一个GridView1,页面运行时能显示数据,并且选择按钮的时候,能成功执行以下代码:
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {
  Label1.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
  Label2.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[2].Text;
  Label3.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[3].Text;
  Label4.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[4].Text;
  Label5.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[5].Text;
  Label6.Text = this.GridView1.Rows[e.NewSelectedIndex].Cells[6].Text;
  }

现在有个问题是,我想在Button2_Click的代码中调用protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)下的操作,如何调用,请高手帮忙解决,非常感谢!!!!

------解决方案--------------------
你记住
xx=e.NewSelectedIndex的值,然后把上面的代码写成
Label1.Text = this.GridView1.Rows[xx].Cells[1].Text;
写到 Button2_Click 代码里面
------解决方案--------------------
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
{
  
ViewState["nowindex"] = e.NewSelectedIndex;

}


protected void Button2_Click(object sender, EventArgs e)
{
string strIndex=ViewState["nowindex"].ToString();
}