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

  • Home
  • SEARCH
  • 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 6175069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:51:40+00:00 2026-05-23T23:51:40+00:00

Before I was binding my data to my GridView in the .cs file. I

  • 0

Before I was binding my data to my GridView in the .cs file. I had searching/sorting working (search the database by typing in to a textbox, sort by selecting an option from a dropdownlist). However, now I’m binding my data in the .aspx file, and of course my sort/search isn’t working anymore. How can I alter my sorting/searching algorithm so that the correct data binds???

(searchFill is the function that invokes searching/sorting)

.cs

 protected void Page_Load(object sender, EventArgs e)
    {
        rootWebConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("/Cabot3");
        connectionString = rootWebConfig.ConnectionStrings.ConnectionStrings["SecureODBConnectionString"];
        searchFill();
        GridViewRow row = DefaultGrid.SelectedRow;
        int rowIndex = DefaultGrid.SelectedIndex;
        HiddenGrid.SelectedIndex = rowIndex;
        GridViewRow row2 = HiddenGrid.SelectedRow;
        //int id = Convert.ToInt32(row.Cells[25].Text);
        fName = row2.Cells[0].Text;
        lName = row2.Cells[1].Text;
        addr = row2.Cells[2].Text;
        addr2 = row2.Cells[3].Text;
        city = row2.Cells[4].Text;
        state = row2.Cells[5].Text;
        zip = row2.Cells[6].Text;
        country = row2.Cells[7].Text;
        email = row2.Cells[8].Text;
        phone = row2.Cells[9].Text;
        ccType = row2.Cells[10].Text;
        ccNum = row2.Cells[11].Text;
        ccExp = row2.Cells[12].Text;
        length = row2.Cells[13].Text;
        delivery = row2.Cells[14].Text;
        price = row2.Cells[15].Text;
        source = row2.Cells[16].Text;
        joined = row2.Cells[17].Text;
        url = row2.Cells[18].Text;
        orderResults = row2.Cells[19].Text;
        pubName = row2.Cells[20].Text;
        sourceCode = row2.Cells[21].Text;
    }

    protected void searchFill()
    {
        orderByString = orderByList.SelectedItem.Value;
        fieldString = searchTextBox.Text;
        string sqlStatement = "SELECT * FROM SecureOrders WHERE fName LIKE '%" + fieldString + "%' OR lName LIKE'%" + fieldString + "%' OR addr LIKE'%" + fieldString + "%' OR addr2 LIKE'%" + fieldString + "%' OR city LIKE'%" + fieldString + "%' OR state LIKE'%" + fieldString + "%' OR zip LIKE'%" + fieldString + "%' OR zip LIKE'%" + fieldString + "%' OR country LIKE'%" + fieldString + "%' OR email LIKE'%" + fieldString + "%' OR phone LIKE'%" + fieldString + "%' OR ccType LIKE'%" + fieldString + "%' OR ccNum LIKE'%" + fieldString + "%' OR ccExp LIKE'%" + fieldString + "%' OR cwaSource LIKE'%" + fieldString + "%' OR cwaJoined LIKE'%" + fieldString + "%' OR length LIKE'%" + fieldString + "%' OR delivery LIKE'%" + fieldString + "%' OR price LIKE'%" + fieldString + "%' OR url LIKE'%" + fieldString + "%' OR orderResults LIKE'%" + fieldString + "%' OR pubName LIKE'%" + fieldString + "%' OR sourceCode LIKE'%" + fieldString+ "%' ORDER BY " + orderByString;
        using (SqlConnection connection = new SqlConnection(connectionString.ToString()))
        using(SqlCommand searchSort = new SqlCommand(sqlStatement, connection))
        {
            searchSort.Parameters.AddWithValue("@fieldString", fieldString);
            searchSort.Parameters.AddWithValue("@orderByString", orderByString);

            connection.Open();
                searchSort.ExecuteNonQuery();             
            connection.Close();
        }
    }

.aspx

 <asp:GridView ID="DefaultGrid" 
        runat = "server"
        DataKeyNames = "IdentityColumn"
        onselectedindexchanged = "DefaultGrid_SelectedIndexChanged"
        autogenerateselectbutton = "True"
        enableviewstate = "False"
        selectedindex="0" DataSourceID="OrderSource" EnableModelValidation="True" 
        AutoGenerateColumns="False">
    <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>
        <asp:BoundField DataField="fName" HeaderText="First Name" SortExpression="fName" />
        <asp:BoundField DataField="lName" HeaderText="Last Name" SortExpression="lName" />
        <asp:BoundField DataField="addr" HeaderText="Address" SortExpression="addr" />
        <asp:BoundField DataField="email" HeaderText="Email" SortExpression="email" />
        <asp:BoundField DataField="phone" HeaderText="Phone" SortExpression="phone" />
        <asp:BoundField DataField="ccType" HeaderText="Credit Card Type" 
            SortExpression="ccType" />
        <asp:BoundField DataField="length" HeaderText="Length" 
            SortExpression="length" />
    </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="OrderSource" runat="server" 
        ConnectionString="<%$ ConnectionStrings:SecureODBConnectionString %>" 
        SelectCommand="SELECT * FROM [SecureOrders]"></asp:SqlDataSource>
    </div>
  • 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-23T23:51:42+00:00Added an answer on May 23, 2026 at 11:51 pm

    Maybe this…

    1. Write your stored procedure (as @coder says…the way you’re doing it is not secure)

      CREATE PROCEDURE dbo.myPROC
      (@parm1 int = null, @parm2 int = null, …)
      AS
      BEGIN

      SELECT
         field1,
         field2,
         field3,
         ...
      FROM
         Table
      WHERE
         (field1 = @parm1 or @parm1 is null)
         OR
         (field2 = @parm2 or @parm2 is null)
      
      END
      
    2. Configure your datasource (use the wizard).

    Once you identify your stored procedure to the datasource, it will ask you for the source values for each parameter identified in the stored procedure. just fill-in the default value and leave the rest alone. Basically what you want to end-up with is something like this (I’m not getting this syntactically correct — but your intellisense will get it for you once you start):

    ...
    <SELECT PARAMETERS>
       <PARAMETER name="parm1" type="integer">
       ...
    </SELECT PARAMETERS>
    
    1. Modify your searchFill() procedure to use the vars you created in your onload

    me.datasource1.parameters.clear()
    me.datassource.parameters(“parm1”).defaultvalue = fname;
    me.datassource.parameters(“parm2”).defaultvalue = lname;
    …

    1. rebind your gridview

      me.gridview.databind

    This isn’t elegant, but it seems to fit with the approach you have taken so far. Hope it helps.

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

Sidebar

Related Questions

My GridView using following data binding syntax to bind data. I hope do data
I am binding an array to a DataGridView. I have a column containing file
I have problems binding both a telerik RadGrid and a plain vanilla ASP.NET GridView
A simple WPF ListView: <ListView Name=recordContainer ItemsSource={Binding Path=MyCollection}> <GridView> <GridViewColumn Width=260 Header=Name DisplayMemberBinding={Binding Path=Name}/>
Recently I use data binding to speed up my development of C# winforms application.
Odd question as I've never attempted this before in my usual data binds. Say
Before you answer this I have never developed anything popular enough to attain high
Before I start, I know there is this post and it doesn't answer my
Before I do this I figured I would ask if it was the best
Before I jump headlong into C#... I've always felt that C, or maybe C++,

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.