G
Guest
Hello all,
I have a sticky situation that needs an expert solution. Please help!
My ASP.NET page has a datagrid which is bound to a dataset. No surprise
there. As the data is bound and rendered, I add a button to the cell in one
of the columns at run-time in the ItemDataBoundEvent. The button is only
added for rows that meet a specific rule condition. For example, suppose
the rows show books. I only add the "buy" button for books that are in
stock.
When a user clicks the dynamically created "buy" button, a postback occurs.
At that point, I have two options to retrieve the dataset and rebind.
Optiona 1 - I can go to the database again and retreive a fresh set of data.
In this case, if the book associated with the button is no longer in stock,
the button never gets created and the click event never fires. I understand
why this happens but I'd like to at least be able to tell the user "the book
has gone out of stock, please call for availability". Is there a way to get
the object that triggered the postback? If so, I wouldn't have to do option
2 which is...
Option 2 - Store the dataset in the users session and rebind to that on the
postback. This ensures that the postback grid gets drawn exactly as the
user saw it and that the clicked button is rendered so I can receive the
event. In the business rule processing for the event, I check to make sure
the book is in stock and show an error message if it is not. I also refresh
the grid with the latest set of data.
Option 2 is working great right now, but it means I have to put a dataset in
the Session object for each user that hits the page. Ugggghhh.
If you have a suggestion on how to better implement this, please share.
Thanks!
Scott Mitchell
(e-mail address removed)
I have a sticky situation that needs an expert solution. Please help!
My ASP.NET page has a datagrid which is bound to a dataset. No surprise
there. As the data is bound and rendered, I add a button to the cell in one
of the columns at run-time in the ItemDataBoundEvent. The button is only
added for rows that meet a specific rule condition. For example, suppose
the rows show books. I only add the "buy" button for books that are in
stock.
When a user clicks the dynamically created "buy" button, a postback occurs.
At that point, I have two options to retrieve the dataset and rebind.
Optiona 1 - I can go to the database again and retreive a fresh set of data.
In this case, if the book associated with the button is no longer in stock,
the button never gets created and the click event never fires. I understand
why this happens but I'd like to at least be able to tell the user "the book
has gone out of stock, please call for availability". Is there a way to get
the object that triggered the postback? If so, I wouldn't have to do option
2 which is...
Option 2 - Store the dataset in the users session and rebind to that on the
postback. This ensures that the postback grid gets drawn exactly as the
user saw it and that the clicked button is rendered so I can receive the
event. In the business rule processing for the event, I check to make sure
the book is in stock and show an error message if it is not. I also refresh
the grid with the latest set of data.
Option 2 is working great right now, but it means I have to put a dataset in
the Session object for each user that hits the page. Ugggghhh.
If you have a suggestion on how to better implement this, please share.
Thanks!
Scott Mitchell
(e-mail address removed)