Categories
askquestion

Gridview disappears when page is refreshed

Gridview disappears when page is refreshed

Ask Question

Asked
10 years, 6 months ago

Active
5 years, 6 months ago

Viewed
2k times

.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{
margin-bottom:0;
}

0

I have a gridview that is being populated from a sql database.
When the results are displayed I am linking the district #’s to a new contact page for each one. Ex. d1.aspx, d2.aspx, d3.aspx etc. On each of those pages there is a link to return back to the orginal page. When this happens the original page is refrreshed and the previous gridview results are gone. Is it possible to stop this from happening or is there a better way to do something like this?

<Columns>
<asp:BoundField HeaderText=”Name” DataField=”school” /><asp:BoundField />

<asp:TemplateField HeaderText=”District” HeaderStyle-HorizontalAlign=”Left”>
<ItemTemplate>
<asp:HyperLink ID=”HyperLink1″ runat=”server” NavigateUrl='<%# Eval(“district”, “cdms/d{0}.aspx”) %>’ Text='<%# Eval(“district”) %>’>

</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
</Columns>

<EmptyDataTemplate>
<span style=”color: rgb(255, 0, 0);”>No records found!</span>
</EmptyDataTemplate>
</asp:GridView>

Codebehind:

protected void btnSubmit_Click(object sender, EventArgs e)
{
BuildGridView1();
GridView1.DataBind();
GridView1.Visible = true;
}

private void BuildGridView1()
{
GridView1.DataSource = new Select(District.Schema.TableName + “.*”)
.From(District.Schema)
.Where(District.Columns.Zip).IsEqualTo(this.txtZip.Text)
.OrderAsc(District.Columns.Zip)
.ExecuteDataSet();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
BuildGridView1();
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}

asp.net gridview

share|improve this question

edited Sep 15 ’09 at 16:56

Brett

asked Sep 15 ’09 at 14:24

BrettBrett

7511 gold badge22 silver badges88 bronze badges

Can you add your Page_Load event code to make sure it’s not messed up?

– Jim W
Sep 15 ’09 at 15:35

There is nothing in the page load event.

– Brett
Sep 15 ’09 at 15:54

How are you binding your datasource to the GridView?

– NakedBrunch
Sep 15 ’09 at 16:47

add a comment
 | 

2 Answers
2

Active

Oldest

Votes

0

There are a lot of different ways to handle this situation. A possible solution for you is to store the user’s query results in a session variable. On page load, check to see if query results exist. If so, populated the GridView from the session variable. If not, hit the database for the results and add the result to the session variable.

I haven’t tested it but something like this should work. :

private void BuildGridView1()
{
DataSet ds;
if (Session[“myDataset”] == null)
{
ds = new Select(District.Schema.TableName + “.*”)
.From(District.Schema)
.Where(District.Columns.Zip).IsEqualTo(this.txtZip.Text)
.OrderAsc(District.Columns.Zip)
.ExecuteDataSet();

Session[“myDataset”] = ds;
}
else
{
ds = (DataSet)Session[“myDataSet”];
}
GridView1.DataSource = ds;
}

share|improve this answer

edited Sep 15 ’09 at 17:08

answered Sep 15 ’09 at 14:36

NakedBrunchNakedBrunch

43.7k1313 gold badges6868 silver badges9595 bronze badges

Ok, I see what your saying. I will give it a try. Thanks!

– Brett
Sep 15 ’09 at 17:20

I’d recommend against using session variables just because most people today use multiple tabs in their browsers. If an end-user has two tabs opened, then one tab will overwrite the session variable set by the other tab. Although, this might happen to very few end-users, it is very confusing to them when it does happen. I’d recommend looking at a way to maybe pass the ZIP value via URL parameterto the page and load it that way.

– Jim W
Sep 15 ’09 at 17:30

IE8 maintains sessions across tabs (blogs.msdn.com/ie/archive/2008/07/28/ie8-and-reliability.aspx). I think IE7 does as well as recent Firefox releases. If you’re still concerned about using sessions, you can always store the dataset inside a cache variable and play with the expiry times. The code is similar with some small changes. It’s not ideal but it would likely meet your needs.

– NakedBrunch
Sep 15 ’09 at 18:19

Yes, but that’s not what I’m talking about. If user has 2 tabs with the query page open and queries two different things, the dataset querying in tab 1 will get overwritten by the dataset in tab 2. There’s only 1 session var that’s shared between the two tabs, so if you set it in tab 2, then the old value from tab 1 is overwritten. So if user clicks ‘next page’ in tab 1, it will show page 2 of tab 2’s criteria.

– Jim W
Sep 15 ’09 at 18:21

add a comment
 | 

0

private void BindGridViewServer()
{
DataSet ds =GetData();
GridView1.DataSource = ds;
GridView1.DataBind();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
BindGridViewServer();
}

Make sure EnableSortingAndPagingCallbacks=”False” before you add PageIndexChanging Event.

It works perfectly fine.

share|improve this answer

answered Sep 12 ’14 at 16:34

user4035600user4035600

1

add a comment
 | 

Your Answer

Thanks for contributing an answer to Stack Overflow!Please be sure to answer the question. Provide details and share your research!But avoid …Asking for help, clarification, or responding to other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.

Draft saved
Draft discarded

Sign up or log in

Sign up using Google

Sign up using Facebook

Sign up using Email and Password

Submit

Post as a guest

Name

Email
Required, but never shown

Post Your Answer

Discard

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you’re looking for? Browse other questions tagged asp.net gridview or ask your own question.

The Overflow Blog

Tracking down performance pitfalls in Vue.js

Ways to Help the Fight Against COVID-19 from Home

Featured on Meta

Planned maintenance scheduled for Saturday, March 28, 2020 at 13:00 UTC (9AM…

An Update On Creative Commons Licensing

Community and Moderator guidelines for escalating issues via new response…

How does the Triage queue work?

Triage needs to be fixed urgently, and users need to be notified upon…

Related

4Gridview disappears on postback when paging is enabled1How to get image info from css into MasterPage’gridview?735How do I import a namespace in Razor View Page?0jqGrid-subgrid is not showing up1GridViewRowCommand keep fire0GridView when the page is refreshed0Modal popup extender disappears on gridview refresh2gridview disappears after changing the page2Gridview Paging disappears on adding pagesize

Hot Network Questions

Why don’t folks seem to use ECC for TLS root certificate signature?

Does Giant Killer get destroyed with Warstorm Surge? or is it able to destroy my creature with it’s instant ability?

Is there a “Facebook” for researchers? (to collaborate on projects)

how to draw grease pencil on top of an image easily

How can a Unicorn establish a foreign location as its own lair, when it’s already the lair of a Lich?

How can I get a potential employer to reissue an offer I rejected?

Did Russia release lions onto the streets to keep people in isolation?

What are the objections to Pelosi’s COVID-19 Bill?

VertexContract and contraction of vertices of degree 2

Players get frustrated when they couldn’t solve a hard diplomatic problem, how to get them to think out of the box

Can I create an image with a specific size in bytes?

Cooking shakshuka without burning the tomatoes

Acquaintance paying friend to do his coding for an ivy league masters. What would you do?

Old short story about time travel: not physical, just as onlookers

Counting samples seem to not be Poisson distributed, need sanity check

Birds on a wire (again) – how is it that birds feel no current ? They are just making a paralell circuit, no?

Sci-fi short story about extra sense that can be experienced by humans only once (probably from 1960’s or 70’s)

What’s the proper english name for this mechanical tool to remove bolts of the door?

Abelian category equivalent to a non-abelian category

What version of Divinity is the most recent?

Is it wrong to use a laptop with the lid closed?

What are those large poles for that are always in front of US stand-alone store buildings?

Trying to remove rm a file with ( in its name

Drawing 2.0 A from 9 V battery for 5 seconds

more hot questions

Question feed

Subscribe to RSS

Question feed
To subscribe to this RSS feed, copy and paste this URL into your RSS reader.

default

Leave a Reply

Your email address will not be published. Required fields are marked *