using DataSet and DataView

C

cmrchs

Hi,

I have a table "Colors" in a DataSet with following records :

ID Color
---------
2 Red
7 Green
8 Blue

Then sorting the table using a DataView do the records show as follows :

ID Color
---------
8 Blue
7 Green
2 Red

Now, when I select the last row in the dataView (2, Red) do I want to retrieve the position of that record in the original dataSet, hence rowindex 0 (since it is the first row in the dataSet)

I started with (but don't know how to continue) :
DataView dv = m_dataSet.Tables[0].DefaultView;
??? = dv.Table.Rows[itemClicked] ???

any ideas very welcome

Thanks

Chris


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
W

William Ryan eMVP

Chris:

I think you can just use find on or select to do this. Since you already
know the value of the field (2 in either case) you can access everything in
that column. Typically if you have a grid, this sort of thing comes up.
If that's the case you can just use the Selected row and set the values
directly, they changes will pass through to the datatable regardless of the
sort (but you obviously can't reference the table index in the same context
of the new sort position). If you absolutely can't use Keys to do your
finds, you could create your own index, sticking the ID value in a hashtable
as the value and the 'original' position as the key. This is a rather
indirect route to get there but in a DB this is quite similar to the
physical implementation of indexes .

Not sure if this answered your question or not, but I think it did if I
understood it correctly. If not, let me know.

Bill

www.devbuzz.com
www.knowdotnet.com

Chris C said:
Hi,

I have a table "Colors" in a DataSet with following records :

ID Color
---------
2 Red
7 Green
8 Blue

Then sorting the table using a DataView do the records show as follows :

ID Color
---------
8 Blue
7 Green
2 Red

Now, when I select the last row in the dataView (2, Red) do I want to
retrieve the position of that record in the original dataSet, hence rowindex
0 (since it is the first row in the dataSet)
I started with (but don't know how to continue) :
DataView dv = m_dataSet.Tables[0].DefaultView;
??? = dv.Table.Rows[itemClicked] ???

any ideas very welcome

Thanks

Chris


**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 
C

cmrchs

Hi Bill,

thanks for your suggestion, yes I could use the exisitng row from the DataView only it doesn't work in my scenario 'cause I want to pass on the DataRow for 1 webpage to another.

Therefore do I need do make the dataRow serializable or else I get an error.

So I thought : why not just pass the rowID of the corresponding row in the dataSet.

There must be an easy way to get that corresponding row. No ?

thnx

Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
 
W

William Ryan eMVP

Hi Chris:

I answered above about the session state issue. That can be fixed so are
there any other problems with this method?

Bill

www.devbuzz.com
www.knowdotnet.com

Chris C said:
Hi Bill,

thanks for your suggestion, yes I could use the exisitng row from the
DataView only it doesn't work in my scenario 'cause I want to pass on the
DataRow for 1 webpage to another.
Therefore do I need do make the dataRow serializable or else I get an error.

So I thought : why not just pass the rowID of the corresponding row in the dataSet.

There must be an easy way to get that corresponding row. No ?

thnx

Chris

**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP &
ASP.NET resources...
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top