protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) //各按钮方法
{
if (e.CommandName == "Editer") //编辑
{
int Rowindex = Convert.ToInt32(e.CommandArgument);
int strid = Convert.ToInt32(this.GridView1.Rows[Rowindex].Cells[0].Text);
Response.Write("<script language='JavaScript'>window.location='Edit.aspx?id="+strid+"';</script>");
}
protected void GridView1_RowBound(object sender, GridViewRowEventArgs e)
{
SqlCommand sqlComm;
sqlComm = new SqlCommand();
sqlComm.Connection = sqlConn;
if (e.Row.RowType == DataControlRowType.DataRow)
{//绑定DropDownList
DropDownList ddlModel = (DropDownList)e.Row.FindControl("ddlModel"); //先绑定dropdownlist
strSQL = "SELECT * FROM tModel";
sqlComm.CommandText = strSQL;
sqlComm.Connection.Open();
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = sqlComm;
DataSet ds = new DataSet();
sda.Fill(ds, "tModel");
ddlModel.DataSource = ds.Tables["tModel"];
ddlModel.DataTextField = "MText";
ddlModel.DataValueField = "ID";
ddlModel.DataBind();
sqlComm.Connection.Close();
}
}