gridview paging oddity

  • Thread starter Thread starter JohnE
  • Start date Start date
J

JohnE

Here is an oddity that is now occurring with a gridview. There is a gridview
on a page. As part of the page there is a search button. Now, as of late
yesterday all was working fine just like it should. Then what began occuring
is the Search button had to be double clicked for the gridview.allowpaging =
false to work. In debugging, it runs thru the code just like it should
without error the first time thru and loads the page as planned. I type
something in the Search box (there should be 20 records found) and click the
Search button. The code runs thru the Search just it should and hits all
lines of code without error. One line is the allowpaging = false and it
shows false when hovering over it. But, this line does not work until the
second click of the Search button. And debugging goes over the entire
process again like it did on the first click of the Search button. Here is
the code that is used.

if (!String.IsNullOrEmpty(txtSearch.Text))
{
SearchExpression = string.Format("{0}'%{1}%'",
GridView1.SortExpression, txtSearch.Text);
dv.RowFilter = "ChangeRequest like " + SearchExpression;
GridView1.DataSource = dv;
GridView1.DataBind();
GridView1.AllowSorting = false;
GridView1.AllowPaging = false;
ddlNumberPerPage.Enabled = false;
}

From when it was working correctly to when it started the double click
nothing was added or done to the webapp. This is all on a pc with no server
involved other then what the machine creates during runtime.

Any thoughts on this?

Thanks... john
 
A couple of thoughts....

Where is the code you're showing below added into the page class's event
handling?

Typically, when you encounter something not working on the first click, but
it does work on the second, it has to do with DataBind being called at the
wrong time. So, try moving the GridView1.DataBind(); to be the last line of
code in the code (outside of the if block).

-Scott
 
JohnE said:
Here is an oddity that is now occurring with a gridview. There is a gridview
on a page. As part of the page there is a search button. Now, as of late
yesterday all was working fine just like it should. Then what began occuring
is the Search button had to be double clicked for the gridview.allowpaging =
false to work. In debugging, it runs thru the code just like it should
without error the first time thru and loads the page as planned. I type
something in the Search box (there should be 20 records found) and click the
Search button. The code runs thru the Search just it should and hits all
lines of code without error. One line is the allowpaging = false and it
shows false when hovering over it. But, this line does not work until the
second click of the Search button. And debugging goes over the entire
process again like it did on the first click of the Search button. Here is
the code that is used.

if (!String.IsNullOrEmpty(txtSearch.Text))
{
SearchExpression = string.Format("{0}'%{1}%'",
GridView1.SortExpression, txtSearch.Text);
dv.RowFilter = "ChangeRequest like " + SearchExpression;
GridView1.DataSource = dv;
GridView1.DataBind();
GridView1.AllowSorting = false;
GridView1.AllowPaging = false;
ddlNumberPerPage.Enabled = false;
}

From when it was working correctly to when it started the double click
nothing was added or done to the webapp. This is all on a pc with no server
involved other then what the machine creates during runtime.

Any thoughts on this?

Thanks... john

Ok. I might have gotten it resolved. I moved the paging, sorting, and
enable lines ahead of the IF line. Now only one button click is needed.
.... John
 
You're still going to need to put the DataBind line AFTER the if{} block,
because you want to databind whether there is search criteria or not..
 
Scott M. said:
You're still going to need to put the DataBind line AFTER the if{} block,
because you want to databind whether there is search criteria or not..

Not necessarily. If there isn't anything found in the search, then the grid
shows nothing and the no data text shows. The users need to know whether
there is or isn't any data found. Visually they will see there is no data
(along with the text). If the grid rebinds during the search, the user might
think there was info found. Then when they start looking at it and find it
did not produce a proper search, they will be on the phone to IT (or me)
complaining that the search doesn't work. I placed a button below the grid
that will return the gridview back to its original state. The grid use might
seem odd with all this but manufacturing medical devices there cannot be
assumptions especially when the FDA does an audit.
John
 
If your search tunrs up no results, then your grid will be bound to those
results (none), so there won't be any data for the user to erroneously get.

-Scott
 
Scott M. said:
If your search tunrs up no results, then your grid will be bound to those
results (none), so there won't be any data for the user to erroneously get.

-Scott

I see your point. Will test it both ways to make sure the return info is
the same. Thanks for pointing that out.
John
 
Back
Top