gridview sorting is not working

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default gridview sorting is not working

    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.ConnectionStrin gs["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 Guest

  2. Similar Questions and Discussions

    1. GridView doesn't appear
      Hi, I am using the control GridView. I can see this control in html document in design view, but when I run it, it will not show up, neither the...
    2. Sorting not working correctly
      Hey, I am trying to do the same as described here (http://www.wintellect.com/forum/topic.asp?TOPIC_ID=709). The only difference is that I have...
    3. GridView paging/sorting - will it work with stored procedures?
      Can anyone tell me whether the new ASP.NET 2.0 GridView control supports sorting and paging when the data source is a SQL stored procedure, e.g....
    4. please DataGrid vs. GridView
      GridView is a more functional Control in Whidbey
    5. What is the GridView?
      Hey Folks. Who can tell us all more about the GridView in http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx the successor to the DataGrid?...
  3. #2

    Default RE: gridview sorting is not working

    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.ConnectionStrin gs["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 Guest

  4. #3

    Default Re: gridview sorting is not working

    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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139