第一步:
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);
}
}