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 6149811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:30:58+00:00 2026-05-23T19:30:58+00:00

I’m using AJAX right now to update my GridView when I search for a

  • 0

I’m using AJAX right now to update my GridView when I search for a string of text in the gridview, or when I select from a dropdownlist what I want to order the Gridview by. This was working previously, but I had really messy code. So I’ve cleaned it up a little bit, added some parameters and such. Unfortunately, now, when the selectedindex of the dropdownlist is changed or when someone tries to search for a field, nothing happens – the page just refreshes. I’m also getting an exception saying “The SELECT item identified by the ORDER BY number 1 contains a variable as part of the expression identifying a column position. Variables are only allowed when ordering by an expression referencing a column name”.

If you need to see any more code then please let me know!

public vieworders()
    {
        this.PreInit += new EventHandler(vieworders_PreInit);
    }

    void vieworders_PreInit(object sender, EventArgs e)
    {
            orderByString = orderByList.SelectedItem.Value;
            fieldString = searchTextBox.Text;
            updateDatabase(fieldString, orderByString);

    }

    protected void updateDatabase(string _searchString, string _orderByString)
    {
        string updateCommand = "SELECT fName,lName,zip,email,cwaSource,price,length FROM SecureOrders WHERE fName LIKE @searchString OR lName LIKE @searchString OR zip LIKE @searchString OR email LIKE @searchString OR cwaSource LIKE @searchString OR length LIKE @searchString OR price LIKE @searchString ORDER BY @orderByString";

        Configuration rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Cabot3");
        ConnectionStringSettings connectionString = rootWebConfig.ConnectionStrings.ConnectionStrings["secureodb"];

        // Create an SqlConnection to the database.
        using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
        using (SqlCommand _fillDatabase = new SqlCommand(updateCommand, connection))
        {

            connection.Open();
            _fillDatabase.Parameters.Add("@searchString", SqlDbType.VarChar, 50).Value = _searchString;
            _fillDatabase.Parameters.Add("@orderByString", SqlDbType.VarChar, 50).Value = _orderByString;
            _fillDatabase.ExecuteNonQuery();

            dataAdapter = new SqlDataAdapter("SELECT * FROM SecureOrders", connection);

            // create the DataSet
            dataSet = new DataSet();
            // fill the DataSet using our DataAdapter               
            dataAdapter.Fill(dataSet, "SecureOrders");

            DataView source = new DataView(dataSet.Tables[0]);
            DefaultGrid.DataSource = source;
            DefaultGrid.DataBind();
            connection.Close();
        }
    }

Form

<form id="form1" runat="server">
<asp:ScriptManager ID = "ScriptManager" runat="server" />
    <div>
        <asp:Label runat="server" id = "orderByLabel" Text = "Order By: " />


        <asp:DropDownList runat="server" ID="orderByList" AutoPostBack="true">
            <asp:ListItem Value="fName" Selected="True">First Name</asp:ListItem>
            <asp:ListItem Value="lName">Last Name</asp:ListItem>
            <asp:ListItem Value="state">State</asp:ListItem>
            <asp:ListItem Value="zip">Zip Code</asp:ListItem>
            <asp:ListItem Value="cwaSource">Source</asp:ListItem>
            <asp:ListItem Value="cwaJoined">Date Joined</asp:ListItem>
        </asp:DropDownList>
    </div>
    <div>
        <asp:Label runat="server" ID="searchLabel" Text="Search For: " />
        <asp:TextBox ID="searchTextBox" runat="server" Columns="30" />
        <asp:Button ID="searchButton" runat="server" Text="Search" />
    </div>
<div>
<asp:UpdatePanel ID = "up" runat="server">



    <ContentTemplate>
    <div style= "overflow:auto; height:50%; width:100%">
    <asp:GridView ID="DefaultGrid" runat = "server" DataKeyNames = "IdentityColumn"
    onselectedindexchanged = "DefaultGrid_SelectedIndexChanged"
    autogenerateselectbutton = "true">
    <SelectedRowStyle BackColor="Azure"
    forecolor="Black"
    font-bold="true" />
    <Columns>
    <asp:TemplateField HeaderText="Processed">
                <ItemTemplate>
                    <asp:CheckBox ID="CheckBoxProcess" AutoPostBack = "true" Checked ='<%#Eval("processed") %>' OnCheckedChanged="CheckBoxProcess_CheckedChanged"  runat="server" Enabled="true" />
                </ItemTemplate>
            </asp:TemplateField>
    </Columns>
    </asp:GridView>
    </div>
    </div>
    <div style= "overflow:auto; height:50%; width:100%" />
    <table border="1">
        <tr>    
        <td>Name: </td>
        <td><%=name %></td>
        </tr>
        <tr>
        <td>Zip: </td>
        <td><%=zip %></td>
        </tr>
        <tr>
        <td>Email: </td>
        <td><%=email %></td>
        </tr>
        <tr>
        <td>Length: </td>
        <td><%=length %></td>
        </tr>
        <tr>
        <td>Price: </td>
        <td><%=price %></td>
        </tr>
        <tr>
        <td>Source: </td>
        <td><%=source %></td>
        </tr>
    </table>
    </div>
    </ContentTemplate>
    </asp:UpdatePanel>



</div>
</form>
  • 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-23T19:30:59+00:00Added an answer on May 23, 2026 at 7:30 pm

    I have never used the UpdatePanel since my company uses Telerik, but from the examples I see during my research I remember seeing a trigger component.

    From my understanding, if the control is w/i the UpdatePanel itself, then you do not have to specify the trigger, since it is assumed.

    For your scenario, the trigger (dropdownlist) is outside of the UpdatePanel. You may need to include this in your aspx:

    <asp:UpdatePanel ID = "up" runat="server">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="orderByList" >
    </Triggers>
    <ContentTemplate>
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
this is what i have right now Drawing an RSS feed into the php,
I have a text area in my form which accepts all possible characters from
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string
I have a bunch of posts stored in text files formatted in yaml/textile (from
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.