第一步:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btn = (Button)e.Row.Cells[3].Controls[0];
btn.CommandArgument = e.Row.RowIndex.ToString();
}
}
第二步:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
if (e.CommandName == "query")
{
string startTime =((TextBox)this.GridView1.Rows[rowIndex].Cells[1].FindControl("ConvertDate1").FindControl("txbTime")).Text;
Response.Write(startTime);
}
}

本文详细介绍了ASP.NET中GridView控件的使用方法,包括如何通过RowCreated事件设置按钮的CommandArgument属性来标识行索引,以及如何在RowCommand事件中获取特定行的数据并进行处理。
113

被折叠的 条评论
为什么被折叠?



