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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:49:07+00:00 2026-05-26T21:49:07+00:00

I have a gridview with paging enabled and a textbox where the user can

  • 0

I have a gridview with paging enabled and a textbox where the user can enter a string value used to select the row in the gridview with a column that matches the string value. The column’s data is not the primary key and is not listed in the datakeynames.

I’ve found an example that solves the problem for a non-paging gridview. In an event handler for a button control associated with the textbox:

    protected void SelFrame_Clicked(object sender, EventArgs e)
    {
        string requestedFrame = tbSelFrame.Text;
        if (requestedFrame != "")
        {
            int index = (from DataControlField col in gvFrame.Columns
                            where col.HeaderText == "Name"
                            select gvFrame.Columns.IndexOf(col)).FirstOrDefault();

            var query = from GridViewRow row in gvFrame.Rows
                        where row.Cells[index].Text == requestedFrame
                        select row;
            GridViewRow result = query.FirstOrDefault();
            if (result != null)
            {
                int selectedIndex = result.DataItemIndex;
                if (selectedIndex > -1)
                    gvFrame.SelectedIndex = selectedIndex;
            }
        }
    }

As noted, when the value being searched is on a non-visible page of the gridview, this line returns null:

 GridViewRow result = query.FirstOrDefault();

How can I find the matching row in a gridview with paging enabled?

  • 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-26T21:49:07+00:00Added an answer on May 26, 2026 at 9:49 pm

    You should add the value as a datakey instead, and then do something like this:

    gvFrame.SelectedIndex = gvFrame.Rows.Cast<GridViewRow>().First(r => 
        (string)gvFrame.DataKeys[r.RowIndex]["foo"] == requestedFrame).RowIndex;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have GridView which I can select a row. I then have a button
I have a GridView with paging enabled. When I select a different page in
I have a user control that has a gridview in it with paging. The
I have an ASP.NET GridView with paging enabled. The list of page indexes are
I have a GridView that allows editing the values in every column, in every
I have a gridview in update panel and I am doing paging in that,
I have a GridView that use a stored procedure for custom paging and sorting
I have a gridview on my page that gets bound to user search results.
I have created a gridview for populating data, and some user control (TextBox) to
I have gridview that I am using paging on. I want to pass along

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.