所以你要先在RowCreated(其中Test是按钮的CommandName)
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
LinkButton addButton ;
if (e.Row.RowType == DataControlRowType.DataRow)
{
addButton = (LinkButton)e.Row.Cells[1].Controls[0];
if (addButton != null)
{
if (addButton.CommandName== "Test")
addButton.CommandArgument = e.Row.RowIndex.ToString();
}
}
}
然后在RowCommand事件中
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Test")
{
DropDownList dropTemp = (DropDownList)GridView1.Rows[Convert.ToInt32(e.CommandArgument)].Cells[2].FindControl("dropTemp");
if (dropTemp != null)
{
Response.Write(dropTemp.Text);
}
}
}