有2个页面,第一个页面是搜索数据然后放到Session,第二个页面是将Session里的数据绑定到GridView上!!!这是第一个搜索数据的页面protected void Button1_Click(object sender, EventArgs e)
{
ConnectDd();
}
private void ConnectDd()
{
using (SqlConnection conn = new SqlConnection(@"Data Source=PC2009102316FKU\NEWSQL;Initial Catalog=my_site;User ID=sa;Password=122159575"))
{ SqlDataAdapter sda = new SqlDataAdapter("select * from Customer where vlanID like '%" + TextBox1.Text + "%'", conn);
DataTable datatable = new DataTable();
Session["sessionname"] = datatable;
conn.Close();
}
}
}
这是第二个页面,接收Session里的数据到GridView里,但是不成功,我该怎么弄呢???
{
ConnectDd();
}
private void ConnectDd()
{
using (SqlConnection conn = new SqlConnection(@"Data Source=PC2009102316FKU\NEWSQL;Initial Catalog=my_site;User ID=sa;Password=122159575"))
{ SqlDataAdapter sda = new SqlDataAdapter("select * from Customer where vlanID like '%" + TextBox1.Text + "%'", conn);
DataTable datatable = new DataTable();
Session["sessionname"] = datatable;
conn.Close();
}
}
}
这是第二个页面,接收Session里的数据到GridView里,但是不成功,我该怎么弄呢???
{
DataTable d = (DataTable)Session["sessionname"];
GridView1.DataSource = d.DefaultView ;
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
DataTable ds = new DataTable();
ds = (datatable)session["sessionname"];
sda.Fill(ds);
GridView2.DataSource = ds;
GridView2.DataBind();
}
{
DataTable ds = new DataTable();
ds = (datatable)session["sessionname"];
sda.Fill(ds);GridView2.DataSource = ds.DefaultView ;
GridView2.DataBind();
}
DataSet ds=new DataSet();
sda.Fill(ds);
DataTable dt=ds.Tables[0]
Session["sessionname"] = dt;
conn.Close();if( Session["sessionname"] != null)
{
DataTable dt = Session["sessionname"] as DataTable;
GridView1.DataSource =dt ;
GridView1.DataBind();
}