CodeKicks.com
Focus on Microsoft Technologies - Tutorials, Articles, Code Samples.

Saturday, September 02, 2006

Data Grid Paging Sorting

private void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            BindData(null);
            ViewState["sortKey"]="";
        }            
    }
    private void BindData(string sortKey)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath("Kitap.xml"));
       DataView dv1 = ds.Tables["Orders"].DefaultView;
        if (sortKey != null && sortKey != String.Empty)
        {
            dv1.Sort = sortKey;
        }
        dg1.DataSource = dv1;
       dg1.DataBind();

    }
    protected void dg1_Change(object sender, DataGridPageChangedEventArgs e)
    {
        dg1.CurrentPageIndex = e.NewPageIndex;
        BindData(ViewState["sortKey"].ToString());


    }
    protected void dg1_Sort(object sender, DataGridSortCommandEventArgs e)
    {

        string sortKey = e.SortExpression;
        ViewState["sortKey"] = sortKey;
        BindData(sortKey);
    }
    #region Web Form Designer generated code   ...

    override protected void OnInit(EventArgs e)
    {
        //
        // CODEGEN: This call is required by the ASP.NET Web Form Designer.
        //
        InitializeComponent();
        base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        this.Load += new System.EventHandler(this.Page_Load);

    }
    #endregion

Post a Comment