Datalist refresh

  • Thread starter Thread starter Simon Rigby
  • Start date Start date
S

Simon Rigby

Hi folks,

This seems to have been asked quite a bit but the solutions either dont
pertain to my case or the only response is to supply code. So here's
the question and the code is at the bottom.

I have a datalist which is displaying images in a gallery. Each image
has a pair of buttons to promote or demote the image in the list.

A little explanation about the code. The back end database contains two
tables Image and Gallery. Image contains a path to the image, an unique
ID a foreign key to the Gallery table to determine gallery membership
and an integer sequence number to determine the order it appears within
a gallery.

GalleryQuery is a class with a number of static methods that perform
operation on the backend sql server database. I'll refer to it as GQ in
the following for brevity

GQ.GetMinimumSequenceNumber gets the lowest sequence number for a given
gallery

GQ.GetMaximumSequenceNumber gets the highest sequence number for a
given gallery

GQ.GetSequenceNumber gets the sequence number for a specific image

GQ.PromoteImage swaps the sequence number of the chosen image with the
one above.

GQ.DemoteImage swaps the sequence number of the chosen image with the
one below

All of the above works as expected and if I check the backend database
after clicking a promote or demote button the relevent switch has
occured. Reviewing the page shows the switch has occured, however I
can't find a way of making the refresh occur without doing a
response.redirect or server.transer back to the same page.
Unfortunately there are other controls on the page that lose their
state as a result.

I'm assuming that some thing is required at the points marked // ??? in
the code.

Any help greatly appreciated.

protected void CommandFunction(object source, DataListCommandEventArgs
e) {
int gallery = int.Parse(lstGallery.SelectedValue);
int min = GalleryQuery.GetMinimumSequenceNumber(gallery);
int max = GalleryQuery.GetMaximumSequenceNumber(gallery);
int current =
GalleryQuery.GetSequenceNumber(int.Parse(e.CommandArgument.ToString()),
gallery);
int currentImage = int.Parse(e.CommandArgument.ToString());

if (e.CommandName == "MoveUp") {
if (current > min) {
GalleryQuery.PromoteImage(currentImage, gallery);
// ???
}
} else if (e.CommandName == "MoveDown") {
if (current < max) {
GalleryQuery.DemoteImage(currentImage, gallery);
// ???
}
}
}
 
if you change the database, you need to rebind the datalist

-- bruce (sqlwork.com)
 
doh. I cant believe I missed that. Moral of the story is stop trying to
multi task. I should know as a male that doesn't work.

Thanks Bruce (I'll be in the corner)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top