protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "transfer ")
{
int index = Convert.ToInt32(e.CommandArgument);
GridView1.SelectedIndex = index;
DropDownList drpSort = GridView1.Rows[index].FindControl( "droSort ") as DropDownList;
Label lblId = GridView1.Rows[index].FindControl( "lblID ") as Label;
StringBuilder sbUpdate = new StringBuilder( "update CV_Friend set friendsort = ");
sbUpdate.Append(drpSort.SelectedValue);
sbUpdate.Append( " where Id = ");
sbUpdate.Append(lblId.Text);
Response.Write(sbUpdate.ToString());
Response.End();
try
{
SqlHelper.ExecuteNonQuery(WebConfig.WWWChinavalueDbConnectionString, CommandType.Text, sbUpdate.ToString());
}
catch
{
ShowClientMessegeBox( "转移失败! ");
}
}
}
------解决方案--------------------------------------------------------
int index = Convert.ToInt32(e.CommandArgument);
===========================================
你的按钮列必须是ButtonField