Professional Web Applications Themes

datagrid created from a view - ASP.NET General

Hello, I have a datagrid populated with rows from a view. Because they are from a view, the rows are not actual database records, and therefore lack unique identifiers. So I have a command button for each row. When the button is pressed, I want to go to another page with all the information in that selected row. Normally I would do this (if the rows are actual records, that is) //take the datakey value string selected_id = dgMyDataGrid.DataKeys[e.Item.ItemIndex] //and do this before tranfering to another page. Context.Items.Add("uniquekey", selected_id); Then on the second page, I would take the selected_id and ...

  1. #1

    Default datagrid created from a view

    Hello,

    I have a datagrid populated with rows from a view. Because they are from a
    view, the rows are not actual database records, and therefore lack unique
    identifiers.

    So I have a command button for each row. When the button is pressed, I want
    to go to another page with all the information in that selected row.
    Normally I would do this (if the rows are actual records, that is)

    //take the datakey value
    string selected_id = dgMyDataGrid.DataKeys[e.Item.ItemIndex]

    //and do this before tranfering to another page.
    Context.Items.Add("uniquekey", selected_id);
    Then on the second page, I would take the selected_id and retreive the
    record from the database (I've always wondered if that trip to the database
    server would be necessary).

    But I can't even do this with rows from a view because there is no unique
    identifier. But I still want to take the row from the view and give it to
    the destination page.


    David Guest

  2. #2

    Default RE: datagrid created from a view

    Couldn't you just put the data from the selected grid row into an object
    and store that in the context items collection? (Define your own class or
    structure to hold the data, then create an instance of it and place it in
    the items.)

    Then you could pull the object out on page2 and you would have all the data
    you need (rather than just pulling the key out of the context items).

    Hope this helps,
    bliz
    --
    Jim Blizzard
    Sr .NET Developer Evangelist
    Microsoft

    Your Potential. Our Passion.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please reply to newsgroups only, so that others may benefit. Thanks.


    --------------------
    >From: "David" <nospamnospam.com>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >Subject: datagrid created from a view
    >Lines: 24
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <RxJMa.67695$98.2341750twister.socal.rr.com>
    >Date: Wed, 02 Jul 2003 23:04:17 GMT
    >NNTP-Posting-Host: 24.24.137.170
    >X-Complaints-To: [email]abuserr.com[/email]
    >X-Trace: twister.socal.rr.com 1057187057 24.24.137.170 (Wed, 02 Jul 2003
    16:04:17 PDT)
    >NNTP-Posting-Date: Wed, 02 Jul 2003 16:04:17 PDT
    >Organization: RoadRunner - West
    >Path:
    cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfee d-east.nntpserve
    r.com!nntpserver.com!news3.optonline.net!cyclone.r dc-nyc.rr.com!news-east.rr
    com!news-server.columbus.rr.com!cyclone2.kc.rr.com!news2.kc .rr.com!twister.
    socal.rr.com.POSTED!53ab2750!not-for-mail
    >Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31882
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >Hello,
    >
    >I have a datagrid populated with rows from a view. Because they are from a
    >view, the rows are not actual database records, and therefore lack unique
    >identifiers.
    >
    >So I have a command button for each row. When the button is pressed, I
    want
    >to go to another page with all the information in that selected row.
    >Normally I would do this (if the rows are actual records, that is)
    >
    >//take the datakey value
    >string selected_id = dgMyDataGrid.DataKeys[e.Item.ItemIndex]
    >
    >//and do this before tranfering to another page.
    >Context.Items.Add("uniquekey", selected_id);
    >Then on the second page, I would take the selected_id and retreive the
    >record from the database (I've always wondered if that trip to the database
    >server would be necessary).
    >
    >But I can't even do this with rows from a view because there is no unique
    >identifier. But I still want to take the row from the view and give it to
    >the destination page.
    >
    >
    >
    Jim Blizzard [MSFT] Guest

  3. #3

    Default Re: datagrid created from a view

    The datagrid's datasource is a collection object.

    dgMyDataGrid.DataSource = myCollectionObject.

    But I would not know how to make recognize the selected single object within
    the collection when the user selects the row. How would I do that in the
    web environment. I know that is easy in windows forms.
    > Couldn't you just put the data from the selected grid row into an object
    > and store that in the context items collection? (Define your own class or
    > structure to hold the data, then create an instance of it and place it in
    > the items.)
    >
    > Then you could pull the object out on page2 and you would have all the
    data
    > you need (rather than just pulling the key out of the context items).
    >
    > Hope this helps,
    > bliz
    > --
    > Jim Blizzard
    > Sr .NET Developer Evangelist
    > Microsoft
    >
    > Your Potential. Our Passion.
    >
    > This posting is provided "AS IS" with no warranties, and confers no
    rights.
    > Please reply to newsgroups only, so that others may benefit. Thanks.
    >


    David Guest

  4. #4

    Default Re: datagrid created from a view

    But based on the datagrid.SelectedItem.Cells collection you can get the
    cells for the selected row in your datagrid during the postback.

    Add the data from each of the cells to the instance custom class or
    structure, then add that to the cache.

    See the "MyDataGrid_Select" method in the example at :
    [url]http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/[/url]
    frlrfSystemWebUIWebControlsDataGridClassSelectedIn dexTopic.asp.

    Note: if you want to run the VB version that sample code you'll have to
    change the line
    "Dim Cart As DataTable"
    to
    "Dim Cart As New DataTable()"

    Slight bug in the docs.... :)

    Hope this helps,
    bliz

    --
    Jim Blizzard
    Sr .NET Developer Evangelist
    Microsoft

    Your Potential. Our Passion.

    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please reply to newsgroups only, so that others may benefit. Thanks.


    --------------------
    >From: "David" <nospamnospam.com>
    >Newsgroups: microsoft.public.dotnet.framework.aspnet
    >References: <RxJMa.67695$98.2341750twister.socal.rr.com>
    <22GWGxPQDHA.1060cpmsftngxa09.phx.gbl>
    >Subject: Re: datagrid created from a view
    >Lines: 33
    >X-Priority: 3
    >X-MSMail-Priority: Normal
    >X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
    >X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
    >Message-ID: <OjLMa.94107$49.3747870twister.socal.rr.com>
    >Date: Thu, 03 Jul 2003 01:05:50 GMT
    >NNTP-Posting-Host: 24.24.137.170
    >X-Complaints-To: [email]abuserr.com[/email]
    >X-Trace: twister.socal.rr.com 1057194350 24.24.137.170 (Wed, 02 Jul 2003
    18:05:50 PDT)
    >NNTP-Posting-Date: Wed, 02 Jul 2003 18:05:50 PDT
    >Organization: RoadRunner - West
    >Path:
    cpmsftngxa09.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed 00.sul.t-online.de!t-onlin
    e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfee d-east.nntpserve
    r.com!nntpserver.com!news-west.rr.com!cyclone.kc.rr.com!cyclone2.kc.rr.com!n
    ews2.kc.rr.com!twister.socal.rr.com.POSTED!53ab275 0!not-for-mail
    >Xref: cpmsftngxa09.phx.gbl microsoft.public.dotnet.framework.aspnet:31897
    >X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
    >
    >The datagrid's datasource is a collection object.
    >
    >dgMyDataGrid.DataSource = myCollectionObject.
    >
    >But I would not know how to make recognize the selected single object
    within
    >the collection when the user selects the row. How would I do that in the
    >web environment. I know that is easy in windows forms.
    >
    >> Couldn't you just put the data from the selected grid row into an object
    >> and store that in the context items collection? (Define your own class
    or
    >> structure to hold the data, then create an instance of it and place it in
    >> the items.)
    >>
    >> Then you could pull the object out on page2 and you would have all the
    >data
    >> you need (rather than just pulling the key out of the context items).
    >>
    >> Hope this helps,
    >> bliz
    >> --
    >> Jim Blizzard
    >> Sr .NET Developer Evangelist
    >> Microsoft
    >>
    >> Your Potential. Our Passion.
    >>
    >> This posting is provided "AS IS" with no warranties, and confers no
    >rights.
    >> Please reply to newsgroups only, so that others may benefit. Thanks.
    >>
    >
    >
    >
    >
    Jim Blizzard [MSFT] Guest

Similar Threads

  1. Datagrid Combobox itemEditor dynamically created in AS
    By chuckgoss in forum Macromedia Flex General Discussion
    Replies: 2
    Last Post: May 7th, 02:38 PM
  2. Page view issues with newly created links
    By Anoek_Minneboo@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: August 1st, 06:40 PM
  3. Dynamically created control in Datagrid problem
    By L Wanky via DotNetMonster.com in forum ASP.NET Data Grid Control
    Replies: 14
    Last Post: March 8th, 07:54 PM
  4. Maintaining View State For Dynamically Created Controls
    By Earl Teigrob in forum ASP.NET Building Controls
    Replies: 0
    Last Post: October 7th, 08:09 PM
  5. Movie links: created on Mac, view on PC?
    By shawn_girsberger@adobeforums.com in forum Adobe Acrobat Macintosh
    Replies: 0
    Last Post: August 11th, 01:56 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139