Results 1 to 19 of 19

Thread: [RESOLVED] [2005] Add info from a DetailsView in some kind of "Grid"

  1. #1

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Resolved [RESOLVED] [2005] Add info from a DetailsView in some kind of "Grid"

    I am looking for the ASP.NET way of doing this, not looking for how to write a function to do it, that would be to easy and to similar to any other language


    I have one page with a gridview that is filled up with data using a ObjectDataSource component. If you click a link in that grid, you will go to a page with a detailed look of that product, which is mainly a DetailsView component. Now I need a way to click something on this page to add it to the "cart" (like at amazon) which at the moment is a GridView it selv (but if you have a better idea shout out). The cart is presentet to the user in my master page on every page. And will only be updated from this "detailed product" page.

    So what would be the Visual Studio way of copying the data over to that grid in my cart?

    Bonus points to everyone remotly trying to help, even you Mendhak
    - ØØ -

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Add a templatefield to the detailsview control and add an <asp:Button> to the template. Then, you handle the ItemCommand event of the detailsview control. This handles the click event of any control within the detailsview (the detailsview acts like a container). You can give the <asp:Button> a commandname and command argument if you want as well, which you can detect in the itemcommand event using e.CommandName, for example. Once you have this bit set out you can get the data you want out and into your datasource that populates the gridview (your shopping cart). Not sure how you're persisting the data source for the shopping cart but I'll assume you can do that bit yourself and that your alcoholism hasn't killed all your brain cells since the last time I met you.

  3. #3

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Quote Originally Posted by mendhak
    Add a templatefield to the detailsview control and add an <asp:Button> to the template. Then, you handle the ItemCommand event of the detailsview control. This handles the click event of any control within the detailsview (the detailsview acts like a container). You can give the <asp:Button> a commandname and command argument if you want as well, which you can detect in the itemcommand event using e.CommandName, for example.
    I think I got this part, more or less. Remeber I am newer to this than anyone entering this forum section ever before me

    Quote Originally Posted by mendhak
    Once you have this bit set out you can get the data you want out and into your datasource that populates the gridview (your shopping cart). Not sure how you're persisting the data source for the shopping cart but I'll assume you can do that bit yourself and that your alcoholism hasn't killed all your brain cells since the last time I met you.

    Thats the problem. There is no datasource for that cart set up. And I don't think we are supposed to pull the info from the product database either. Unless maybe if we can add one line from the database to this grid (remember this doesn't have to be a gridview, that was an example). Because the only two datasources we can use to pull info out of the table with all the procuts either pull all of them, or pull one using it's name (don't ask why it is not using it's index).

    Thats why I thought getting ALL the info from the detailedView would be a better idea?!? Or should I just get the name form deailView, and then ADD one and one line using datasouce from the database?

    Your humble n00b.

    PS: I have more or less stoped partying as well as drinking. No worries I'm on a helth rebound
    - &#216;&#216; -

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Essentially, you need some sort of a 'source' of data that the 'cart' can read no matter what page it's on. This can be a database (you ruled that out) or even a session variable. From the details page, when the user wants to add to cart, you can store the required information in a session variable. You can store the information either as an object or even in a proprietary XML format that holds your values, but it really depends on what sort of information and how much information you want to hold.

    Once you do that, you can have the 'cart' read from the session variable on every page load (master page).

    Because the only two datasources we can use to pull info out of the table with all the procuts either pull all of them, or pull one using it's name (don't ask why it is not using it's index).

    Thats why I thought getting ALL the info from the detailedView would be a better idea?!?
    Whether you pull one line from the detailsview or all the data from the detailsview depends on what you eventually want to do with your 'cart'. If the user could possibly change the information in the detailsview, and you want to maintain those changes, then you'd obviously store all the data from the detailsview, but if it's just a matter of looking at the data and adding to cart, you could simply store the 'primary' key of the data being looked at.

    As for whether you use a gridview or something else, perhaps it's best if you figure out your storage format first, as displaying the data you persist is a moot point, you could use anything - label, gridview, repeater...

  5. #5

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Ok, you need to walk with me here First the button thingy gave be a quick error, so I traded it for a link All good so far. but if the cart is a gridview, and it read a QueryString for example. Then it will add Kiwi if you choose that, and then if you choose Apple afterwards, it will add claen out the grid view and use the datasource to pull JUST the apple afterwards since it is bound to the function that will pull out one and one column from database instead of adding a new line. So does that mean I can't bind the grid at all?

    Your sencerily more n00b than when you started mulding me an hour ago,
    - &#216;&#216; -

  6. #6
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    With the link, you are probably adding a value to the querystring. But this way, there's only one value in the querystring. Your gridview may read it, but the querystring value was not stored anywhere aside from the querystring itself.


    page.aspx?fruit=kiwi


    Only page.aspx knows that the fruit is 'kiwi'. But page2.aspx will not know this. However, because the cart is in the master page, the cart needs to know what it should have on every page (because the master page is part of page.aspx and page2.aspx).


    This is where session variables come in. A session variable is available to all pages. So you can read

    string x = Session["fruit"].ToString();

    on page.aspx and page2.aspx.


    You'll still need to go back and add the button and overcome that ghastly error. It is a bit more complicated than a simple link, but it gets the job done.

  7. #7

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Ok, I think I need to do some reading about template fields. Just to let you have a laugh. This is what I did. I just switched to source view and added the button:


    Code:
            <Fields>
                <asp:BoundField DataField="ProduktId" HeaderText="ProduktId" SortExpression="ProduktId" />
                <asp:BoundField DataField="Navn" HeaderText="Navn" SortExpression="Navn" />
                <asp:BoundField DataField="Beskrivelse" HeaderText="Beskrivelse" SortExpression="Beskrivelse" />
                <asp:BoundField DataField="Pris" HeaderText="Pris" SortExpression="Pris" />
                <asp:BoundField DataField="ProduktKatId" HeaderText="ProduktKatId" SortExpression="ProduktKatId" />
                <asp:TemplateField>
                    <asp:Button runat="server" Text="Button" />
                </asp:TemplateField>
            </Fields>
    And the highlighted part of the code here, gets a red underline in VS. I bet there is a perfectly good reason for this. But at the moment it beats me *now off to read*

  8. #8

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    <ItemTemplate>

    Was that all? Wow, when the magic doesn't help you in VisualStudio, you get cought with your pants down...

    OK, session variables next. Something tells me this is done quite differently than in lets say PHP and Python...

    - &#216;&#216; -

  9. #9
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Stop being so hard on yourself. It's always difficult in the beginning but once you learn one concept, the others start falling into place, like your pants around your ankles.

    I assume you were able to handle the ItemCommand?

    I think session variables will be done the same way. Just assign it

    Session("fruit") = "kiwi"

    or

    Session("fruit")="kiwi,guava,mango"

  10. #10

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    I went to bed after that really. I didn't even dare to try without reading more. But it says nothing about ItemCommand in my book. Nowhere to be found. Are you sure I need to find out what that is?

    WOuldn't it be the same to use the "OnClientClick" on the button it self?

    ANd if not, did you mean something like?

    Code:
        protected void DetailsView1_ItemCommand(object sender, DetailsViewPageEventArgs e)
        {
            //session concatination here?
        }

    - &#216;&#216; -

  11. #11
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Your book, to put it politely, "draws into the mouth by creating a practical vacuum in the mouth" (in other words, sucks).

    In your ASPX, go to the detailsview tag,

    Code:
    OnItemCommand="DetailsView1_ItemCommand"
    Then you have your event ready. Now look at e.CommandName and e.CommandArgument.

  12. #12

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    I am pretty sure I saw a picture of Wossy on the cover

    Ok, magic happend back and forth. things are happening now. I just hope I have enough time to make those sessions work now.

    Thanks a lot. At least the themes and master pages works as they should. They are both pretty and cute. Pink ponies..woooohoooo...

    Cheers,
    - &#216;&#216; -

  13. #13
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Hurrah! You're on your way to becoming a proper web developer, without that silly PHP/Python.

    Postback if you're stuck. (That's a pun, did you get it?)

  14. #14

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    AutoPostBack was set to False, so, no I did not understand

    Ok, I have to bite the dust one last time. The button has a command name, but how do I send information about the data in the detailsview when you click the button?!?

    Because in the ItemCommand, I can't do something simple like:

    Label1.Text = (string)DetailsView1.SelectedValue;

    because the label shows nothing. Does it get sendt by default, or was that what you meant about the "command argument" I should set. And if so, how do I set it


    Sessions and the rest is fixed now. It's only this bit I am missing

    - &#216;&#216; -
    Last edited by NoteMe; Mar 21st, 2008 at 08:50 AM.

  15. #15
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Not 100% sure what you're looking for there... but .SelectedIndex/.SelectedValue won't make a lot of sense with details view, since you only have one item. Try accessing the value using...

    DetailsView1.Rows[0].Cells[1].Text

    as an example.

  16. #16
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Not 100% sure what you're looking for there... but .SelectedIndex/.SelectedValue won't make a lot of sense with details view, since you only have one item. Try accessing the value using...

    DetailsView1.Rows[0].Cells[1].Text

    For example.

  17. #17

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    Now that was right on. All good now. NOw I can spend the rest of my time drawing doodles on this project And I can see you havn't changed much around here since last time


    You have given out too much Reputation in the last 24 hours, try again later.

    Thanks a million, you saved me from this faulty book of utter wisdom...
    - &#216;&#216; -

  18. #18
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [2005] Add info from a DetailsView in some kind of "Grid"

    I see you've changed a bit, but not much. You're still trying to "rep" everything that moves.

  19. #19

    Thread Starter
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: [RESOLVED] [2005] Add info from a DetailsView in some kind of "Grid"

    Just trying to do the right thing. Just wanted you to know I appreciate you not giving up on me on this one. Thanks again



    - &#216;&#216; -

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width