gridview sorting is not working

Discussion in 'ASP .Net Datagrid Control' started by Abraham Luna, Aug 29, 2005.

  1. Abraham Luna

    Abraham Luna Guest

    can anyone tell me why this code is not working, i've been following the
    tutorials but i can't get it to work:

    <script language="c#" runat="server">

    void Page_Load (Object Sender, EventArgs E)
    {
    if (!Page.IsPostBack)
    {
    BindData(0);
    }
    }

    void btnRefresh_Click(Object Sender, EventArgs E)
    {
    BindData(0);
    }

    void gvCustomers_PageIndexChanging(Object Sender, GridViewPageEventArgs E)
    {
    BindData(E.NewPageIndex);
    E.Cancel = true;
    }

    void BindData(int intPageIndex)
    {
    lblSQL.Text = "SELECT [CusId], [Name], [Addr1] + '<br>' + [City] + ', ' +
    [State] + ' ' + [Post] AS Address, [PhoneWork], [Contact], [EmailWork] FROM
    [COCUS]";
    SqlConnection connRDK = new
    SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ToString());
    SqlDataAdapter daRDK = new SqlDataAdapter(lblSQL.Text, connRDK);
    DataTable dtCustomers = new DataTable();
    daRDK.Fill(dtCustomers);
    daRDK.Dispose();
    connRDK.Close();
    connRDK.Dispose();
    gvCustomers.DataSource = dtCustomers;
    gvCustomers.DataBind();
    gvCustomers.PageIndex = intPageIndex;
    gvCustomers.PageSize = Convert.ToInt32(ddlRPP.SelectedItem.Value);
    lblTotal.Text = dtCustomers.Rows.Count.ToString();
    lblPageIndex.Text = gvCustomers.PageIndex.ToString();
    }

    </script>
     
    Abraham Luna, Aug 29, 2005
    #1
    1. Advertising

  2. Abraham Luna

    Sachin Saki Guest

    Hi,

    daRDK.Dispose();
    connRDK.Close();
    connRDK.Dispose();

    Use Try Catch Block and Place this 3 lines in the Finally Block.

    Regards,
    Sachin Saki
    ..NET Developer : Capgemini - INDIA


    "Abraham Luna" wrote:

    > can anyone tell me why this code is not working, i've been following the
    > tutorials but i can't get it to work:
    >
    > <script language="c#" runat="server">
    >
    > void Page_Load (Object Sender, EventArgs E)
    > {
    > if (!Page.IsPostBack)
    > {
    > BindData(0);
    > }
    > }
    >
    > void btnRefresh_Click(Object Sender, EventArgs E)
    > {
    > BindData(0);
    > }
    >
    > void gvCustomers_PageIndexChanging(Object Sender, GridViewPageEventArgs E)
    > {
    > BindData(E.NewPageIndex);
    > E.Cancel = true;
    > }
    >
    > void BindData(int intPageIndex)
    > {
    > lblSQL.Text = "SELECT [CusId], [Name], [Addr1] + '<br>' + [City] + ', ' +
    > [State] + ' ' + [Post] AS Address, [PhoneWork], [Contact], [EmailWork] FROM
    > [COCUS]";
    > SqlConnection connRDK = new
    > SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ToString());
    > SqlDataAdapter daRDK = new SqlDataAdapter(lblSQL.Text, connRDK);
    > DataTable dtCustomers = new DataTable();
    > daRDK.Fill(dtCustomers);
    > daRDK.Dispose();
    > connRDK.Close();
    > connRDK.Dispose();
    > gvCustomers.DataSource = dtCustomers;
    > gvCustomers.DataBind();
    > gvCustomers.PageIndex = intPageIndex;
    > gvCustomers.PageSize = Convert.ToInt32(ddlRPP.SelectedItem.Value);
    > lblTotal.Text = dtCustomers.Rows.Count.ToString();
    > lblPageIndex.Text = gvCustomers.PageIndex.ToString();
    > }
    >
    > </script>
    >
    >
    >
     
    Sachin Saki, Aug 30, 2005
    #2
    1. Advertising

  3. Abraham Luna

    Abraham Luna Guest

    so sorry, maybe it would help if i explained what isnt working. everything
    works except the gvCustomers_PageIndexChanging

    it doesnt seem to call binddata

    does anyone have an advanced gridview sample that uses: paging, sorting, and
    filtering using webcontrols
     
    Abraham Luna, Aug 30, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Thirsty Traveler

    Column sorting not working in GridView

    Thirsty Traveler, May 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    3,973
    Thirsty Traveler
    May 15, 2006
  2. =?Utf-8?B?TWl0Y2g=?=

    GridView Sorting and paging Not working

    =?Utf-8?B?TWl0Y2g=?=, Jun 12, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    1,177
    =?Utf-8?B?TWl0Y2g=?=
    Jun 12, 2006
  3. Replies:
    2
    Views:
    1,441
    James Kanze
    Jul 6, 2010
  4. Jason
    Replies:
    0
    Views:
    390
    Jason
    Oct 4, 2006
  5. jobs
    Replies:
    2
    Views:
    1,609
Loading...

Share This Page