One for the Experts

Discussion in 'ASP .Net Datagrid Control' started by Guest, Oct 16, 2004.

  1. Guest

    Guest 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
     
    Guest, Oct 16, 2004
    #1
    1. Advertising

  2. Guest

    Damon Payne Guest

    Hi,
    If you want to know what control caused the postback event there are a
    couple of options. You can draw a custom control that implements
    IPostBackHandler and use the built in methods to render postback javascript
    and process postback data; OR
    maybe check the __EVENTTARGET item of the form data and try to figure out
    which one of your buttons this name corresponds to.



    <> wrote in message
    news:%...
    > 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
    >
    >
    >
     
    Damon Payne, Oct 16, 2004
    #2
    1. Advertising

  3. Guest

    Jos Guest

    wrote:
    > 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.


    I have an Option 3.
    I guess you are creating your buttons dynamically in OnItemDataBound.
    Instead, I suggest adding them to the template (statically).
    You only have change their size to 1x1 pixel in OnItemDataBound
    for the ones you don't want the user to see.
    This ensures that your postback will always work.

    If a user inadvertently clicks your 1x1 pixel button, he will get
    an "out of stock" error, which is ok.

    --

    Jos
     
    Jos, Oct 17, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luther Miller

    Here's one for you ASP.NET experts...

    Luther Miller, Jul 3, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    356
    Luther Miller
    Jul 3, 2003
  2. B Wagner
    Replies:
    8
    Views:
    358
    B Wagner
    Aug 18, 2003
  3. Richard

    Ok experts...answer this one

    Richard, Jan 7, 2004, in forum: HTML
    Replies:
    28
    Views:
    833
    Mark Parnell
    Jan 12, 2004
  4. news.frontiernet.net
    Replies:
    6
    Views:
    1,174
    news.frontiernet.net
    Apr 16, 2004
  5. Akram Baig
    Replies:
    0
    Views:
    356
    Akram Baig
    Apr 7, 2011
Loading...

Share This Page