473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.
Nov 17 '05 #1
3 2173
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" <no****@nospam.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: <Rx********************@twister.socal.rr.com>
Date: Wed, 02 Jul 2003 23:04:17 GMT
NNTP-Posting-Host: 24.24.137.170
X-Complaints-To: ab***@rr.com
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-mailXref: 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 wantto 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.


Nov 17 '05 #2
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.


Nov 17 '05 #3
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 :
http://msdn.microsoft.com/library/de...us/cpref/html/
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" <no****@nospam.com>
Newsgroups: microsoft.public.dotnet.framework.aspnet
References: <Rx********************@twister.socal.rr.com> <22**************@cpmsftngxa09.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: <Oj********************@twister.socal.rr.com>
Date: Thu, 03 Jul 2003 01:05:50 GMT
NNTP-Posting-Host: 24.24.137.170
X-Complaints-To: ab***@rr.com
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-mailXref: 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 withinthe 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.



Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Bill C. | last post by:
Hello, I know this has been discussed a lot already because I've been searching around for information the last few weeks. I'm trying to implement a DataGridComboBoxColumn class. I've found...
4
by: Dave bailey | last post by:
When I execute the following code when using a dynamicall created LinkButton in a dynamically created dataGrid, the DataGrid disappears and the page I am trying to get to does not load. Can...
5
by: sdbranum | last post by:
I have been using Visual C#.NET to code a large project having many data adapters, data sets, datagrids, multiple forms with tab pages, each containing various controls (mostly label, text boxes,...
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Ken Varn | last post by:
I have a problem where my DataGrid would not maintain the ViewState of my databound rows. I finally narrowed down the problem. If my first column is a template column, the view state for the...
1
by: sianan | last post by:
I tried to use the following example, to add a checkbox column to a DataGrid in an ASP.NET application: http://www.codeproject.com/aspnet/datagridcheckbox.asp For some reason, I simply CAN'T get...
7
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the...
7
by: GaryDean | last post by:
I am writing a method in a component that gets passed a 1.1 Datagrid. The datagrid's columns were created at run time meaning it has no columns collection. How can I access Header and Footer...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.