protected SqlConnection cn;
protected void Page_Load(Object sender,EventArgs e)
{
//SqlConnection cn;

解决方案 »

  1.   

    SqlConnection cn;
    String strConn="data source=darker; user id=sa; pwd=darker;Initial catalog=eShops";
    cn=new SqlConnection(strConn);protected void Page_Load(Object sender,EventArgs e)
    {
    if (!IsPostBack) 
    {
    BindGrid("ProductId");
    }
    }
    protected void DataGrid_Sort(Object sender,DataGridSortCommandEventArgs E)
    {
    BindGrid(E.SortExpression);}
    public void BindGrid(String sortfield)
    {
    SqlDataAdapter da=new SqlDataAdapter("select * from Products",cn);
    DataSet ds=new DataSet();
    da.Fill(ds);
    DataView view=ds.Tables[0].DefaultView;
    View.Sort=sortfield;
    dgProduct.DataSource=view;
    dgProduct.DataBind();
    }
    </script>