473,714 Members | 2,681 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Da taKeys[e.Item.ItemInde x]

//and do this before tranfering to another page.
Context.Items.A dd("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 2187
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.publi c.dotnet.framew ork.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************ ********@twiste r.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.r r.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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.s yr.edu!news.max well.syr.edu!ne wsfeed-east.nntpserve
r.com!nntpserve r.com!news3.opt online.net!cycl one.rdc-nyc.rr.com!news-east.rr
com!news-server.columbus .rr.com!cyclone 2.kc.rr.com!new s2.kc.rr.com!tw ister.
socal.rr.com.PO STED!53ab2750!n ot-for-mailXref: cpmsftngxa09.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:3188 2
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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.Da taKeys[e.Item.ItemInde x]

//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.Da taSource = myCollectionObj ect.

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.Select edItem.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_Sel ect" method in the example at :
http://msdn.microsoft.com/library/de...us/cpref/html/
frlrfSystemWebU IWebControlsDat aGridClassSelec tedIndexTopic.a sp.

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.publi c.dotnet.framew ork.aspnet
References: <Rx************ ********@twiste r.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************ ********@twiste r.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.r r.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.ph x.gbl!TK2MSFTNG P08.phx.gbl!new sfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.s yr.edu!news.max well.syr.edu!ne wsfeed-east.nntpserve
r.com!nntpserve r.com!news-west.rr.com!cyc lone.kc.rr.com! cyclone2.kc.rr. com!n
ews2.kc.rr.com! twister.socal.r r.com.POSTED!53 ab2750!not-for-mailXref: cpmsftngxa09.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:3189 7
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

The datagrid's datasource is a collection object.

dgMyDataGrid.D ataSource = myCollectionObj ect.

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
4270
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 several examples on the web. They all seem to have problems, though that I've been unable to resolve. The most promising example I have found is at:
4
1779
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 anyone see what is wrong here? protected void Grid_ItemCommand (Object sender, DataGridCommandEventArgs e) { if ( e.CommandName == "Details" ) {
5
2377
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, check boxes, date pickers, combo boxes and datagrids). I have been coding alone on this project for about a year, and I have experienced many problems which have not been addressed by various SP's, including the recent SP1 to Framework.NET 1.1,...
3
4924
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 are Web Control & not HTML control. One of these buttons whose title is Delete is added on the aspx page in design view & also I double clicked on this button in design view to get the onclick code for this button in the code behind page. & for...
3
4878
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 the best method? Do you have a sample of how to do this?
1
1875
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 DataGrid items is not maintained on postback for some reason. I basically re-created my DataGrid again just to make sure this was indeed the problem. The ViewState was fine until I added the template column at the beginning of the Columns list. ...
1
4233
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 the example to work. I created the following two classes, provided with the example: *-*-**-*-*-*-*-*-*-*-*-*-**-*-*-*-*-CheckBoxColumn Class:-*-*-*-*-*-*-*-*-*-*-**-*-*-*-*-**-*-*-*
7
3226
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 column need to be a date picker field. I know things will be easier with ASPX datagrid.
7
7456
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 data in the grid? It's not in the grid.items collection - only rows there. there is no grid.header or grid.footer. --
0
8797
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8704
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5945
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3156
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2107
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.