日期:2014-05-17 浏览次数:20452 次
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = new SqlConnection(ConnectionString);
string sql = "select * from table1";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
DropDownList1.DataSource = ds;
DropDownList1.DataTextField = "name";
DropDownList1.DataValueField = "name";
DropDownList1.DataBind();
string sql2 = "select * from table2";
SqlDataAdapter da2 = new SqlDataAdapter(sql2, conn);
DataSet ds2 = new DataSet();
da2.Fill(ds2);
GridView1.DataSource = ds2;
GridView1.DataBind();
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int index = int.Parse(e.CommandArgument.ToString());
int id = int.Parse(this.GridView1.DataKeys[index].Value.ToString());
if (e.CommandName == "Edit")
{
SqlConnection conn = new SqlConnection(ConnectionString);
string sql = "select * from table2 where id=" + id + "";
SqlDataAdapter da = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
da.Fill(ds);
&nbs