Link to home
Start Free TrialLog in
Avatar of Darshana Bachankar
Darshana Bachankar

asked on

I want to display rows in ascending order in grid view after clicking on button. code has no error but not displaying rows in ascending order.

I want to display rows in ascending order in grid view after clicking on button. here is the code. code has no error but not displaying rows in ascending order.

protected void Button2_Click(object sender, EventArgs e)
    {
        try
        {
            DataTable dt = new DataTable();
            Dbconn.Open();
            string str = "select id,dte from test order by id asc";
            oda = new OracleDataAdapter(str, Dbconn);
            oda.Fill(dt);
            GridView1.DataBind();

        }

        catch (Exception ex)
        {

        }
    }
Avatar of Camillia
Camillia
Flag of United States of America image

It's been a while since I've worked with Gridviews but I think you need to use the "sorting" event of the gridview. It won't sort just by clicking a button.

Here's an example https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.sorting(v=vs.110).aspx
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.