Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3403128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:13:21+00:00 2026-05-18T05:13:21+00:00

I am working on extending an ASP.NET 2.0 application using an InterBase database. My

  • 0

I am working on extending an ASP.NET 2.0 application using an InterBase database. My experience is in PHP/MySQL, so my familiarity with ASP is currently in the 2-week range, and is pieced together from examining a co-worker’s code, the first 90 pages of my ASP book, and Google. In the application, I have an SqlDataSource control connecting to my database and selecting the information I need. Then the results are copied into a DataView where I modify the data in one of the columns, and then I push that DataView to a GridView for output. The issue I’m having is that I cannot sort the GridView at this point. I followed instructions here: http://forums.asp.net/p/956540/1177923.aspx, but to no avail.

Here is the page code:

    <form id="form1" runat="server">
<div>
    <asp:SqlDataSource ID="Products" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
        ProviderName="<%$ ConnectionStrings:ConnectionString1.ProviderName %>" OnLoad="ProductsDS_Load"
        OnSelected="ProductsDS_Selected" DataSourceMode="DataSet">
    </asp:SqlDataSource>

    <br />
    <asp:Label ID="testlabel" runat="server"></asp:Label>
    <br />
    <asp:Label ID="testlabel2" runat="server"></asp:Label>
    <br /><br />
    This table lists all 2000+ numbered projects which are at least partially in process.<br />
    The Project number link leads to a more detailed view of that project.<br />
    <br />
    <asp:Label runat="server" ID="numrows"></asp:Label> results returned.
    <br />
    <asp:GridView ID="ProductsView" runat="server" EnableModelValidation="True" 
        AutoGenerateColumns="False" CellPadding="4" OnSorting="ProductsView_Sorting"
        ForeColor="#333333" GridLines="None" AllowSorting="True">
        <AlternatingRowStyle BackColor="White" />
        <Columns>
            <asp:HyperLinkField HeaderText="Project" SortExpression="PROJECT"
                DataTextField="PROJECT" Target="subweeklyreport" DataNavigateUrlFields="PROJECT"
                DataNavigateUrlFormatString="Products.aspx?p={0}" />
            <asp:BoundField Visible="false" DataField="PROJECTID" />
            <asp:BoundField DataField="PART" HeaderText="Part #" 
                SortExpression="PART" />
            <asp:BoundField DataField="DESCRIPTION" HeaderText="Description" 
                SortExpression="DESCRIPTION" />
            <asp:BoundField DataField="ENGMGR" HeaderText="Eng. Mgr." 
                SortExpression="ENGMGR" />
        </Columns>
        <EditRowStyle BackColor="#7C6F57" />
        <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#E3EAEB" />
        <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
    </asp:GridView>
</div>
</form>

And here is the code behind:

protected void ProductsDS_Load(object sender, EventArgs e)
{

    string SQLQuery = Query would go here;

    testlabel2.Text = SQLQuery;
    Products.SelectCommand = SQLQuery;
    Products.DataBind();

    DataView dv = (DataView)Products.Select(new DataSourceSelectArguments());

    foreach (DataRow dr in dv.Table.Rows)
    {
        string name = dr["ENGMGR"].ToString();
        string[] explode = name.Split(' ');
        string newname;
        if (explode.Length == 3)
        {
            newname = explode[2] + ", " + explode[0];
        }
        else
        {
            newname = explode[1] + ", " + explode[0];
        }

        dr["ENGMGR"] = newname;
        //testlabel.Text = dr["ENGMGR"].ToString();
    }


    Products.DataBind();
    //ProductsView.DataSourceID = "Products";
    ProductsView.DataSource = dv;
    ProductsView.DataBind();
    ProductsView.Enabled = true;
    ProductsView.Visible = true;

}

protected void ProductsDS_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
    numrows.Text = e.AffectedRows.ToString();
}

protected void ProductsView_Sorting(object sender, GridViewSortEventArgs e)
{
    DataTable dataTable = ProductsView.DataSource as DataTable;

    if (dataTable != null)
    {
        DataView dataView = new DataView(dataTable);
        dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);

        ProductsView.DataSource = dataView;
        ProductsView.DataBind();
    }
}

private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
    string newSortDirection = String.Empty;

    switch (sortDirection)
    {
        case SortDirection.Ascending:
            newSortDirection = "ASC";
            break;

        case SortDirection.Descending:
            newSortDirection = "DESC";
            break;
    }

    return newSortDirection;
}

What I think is happening is that whenever the GridView does the postback for the sort, it causes the query to be executed again and overwrite the attempt to sort the existing data in the GridView, but I don’t know enough about ASP right now to prevent this behavior. Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T05:13:22+00:00Added an answer on May 18, 2026 at 5:13 am

    I ended up solving my own problem. I created a session variable to store the dataview between page loads, and checking to see if the dataview is stored before executing the query, and sorting it if it is, and just performing the regular query otherwise. Since I don’t expect data to be introduced between the initial page view and the sort, I don’t think using a stored copy of the data would be a major issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently working on extending a TextView, adding an outline around the text. Thus
I've got a working callback system that uses boost::signal. I'm extending it into a
I'm using a CollapsiblePanelExtender with a checkbox. I would want to make the panel
I've been working as a flex dev for many years, building really complex apps.
I'm working on a game which will use projectiles. So I've made a Projectile
Is it possible to expose the DataContext when extending a class in the DataContext?
I'm working on a tool called Quickfort for the game Dwarf Fortress . Quickfort
I have created a custom view by extending AutoCompleteTextView (with a specialized function called
I have a class that is already extending TabActivity so i can't extend ListActivity.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.