How do you set the current row in a dataset

C

Craig

How do you set the current row of a dataset?
I want to bind a control to a field from the 5th row in a dataset.
I fill the dataset, then I want to set the row to the 5th row and then do
the databinding.

Dataset1.tblMyTable.CurrentIndex = 5 or something like that maybe?



'Sets the value for a field using index number......
Dataset1.tblMyTable(1).FieldName = strName

'Iterates through rows of a dataset but does not set the row
explicitly......
For Each myRow In DataSet1.tblMyTable.Rows
strName = myRow("FieldName")
Next
 
C

Craig

I understand how to do that but it does not do what I need.

The row I want to show is based on the "index" or row number. I may want to
show row 5 then row 100 then row 48. So I need to be able to set the current
row to 5.

How do I do that?
Dataset1.tblMyTable.CurrentIndex = 5 or something like that maybe?
 
E

Eliyahu Goldin

Make a DataView that will contain only the row you want to show and bind
your control to the DataView.

Eliyahu
 
C

Cor Ligthert

Hi Craig,

How do you do that databinding for that 5th row, you makes me curious,

I assume it is aspnet, because if it is windowsform it is easy to tell
however that does not work on a webform.

Cor
 
C

Craig

I am using webforms.

I want to do a 'next page' or 'previous page' function using a web form I
was going to use the row number of the dataset and increment each time or
decrement it each time and rebind the form.

How would I do the 'next page' or 'previous page' functionality using a web
form?

I know I can refer to any row in a dataset but it seems ridiculous that I
can't set the row of a dataset.

Why doesn't the tool box have a next record navigation functionality built
in, Interdev did?
 
C

Cor Ligthert

Are you using a datagrid?

The index is of course the way Eliyahy showed you.

So that I do not need to answer anymore.

Cor
 
C

Craig

No it is using textbox controls on a single page.

I have created a datagrid and set the paging to 1. That worked. But a
complex form can be easier as a webform full of controls.

So any ideas?


Name _________
Address _________
 
C

Cor Ligthert

Hi Craig

In my opinion did you got the idea for that from Eliyahu.

Know that a dataset and your currentindex does not persist when you do not
set it in a session (or a viewstate or a cache, however the last should be a
nonchanging dataset).

Cor
 
C

Craig

Eliyahu said....

Make a DataView that will contain only the row you want to show and bind
your control to the DataView.
and...
Dataset1.tblMyTable.Rows[5] or Dataset1.tblMyTable[5]

I don't see how that helps. I just want to bind the controls to he first
row, then the user clicks a next button and then I'll bind the controls to
the next row etc. I don't care if the dataset has to be refilled etc. and
I'll maintain the current row in a ViewState("Currentrow") variable.

So how can I set the row number in the dataset?

Maybe I'll just stick to a datagrid with paging set to 1.
 
E

Eliyahu Goldin

Dataset1.tblMyTable.Rows[5] or Dataset1.tblMyTable[5]

Is that what you are after?

Eliyahu
 
C

Cor Ligthert

Hi Craig

I translate Eliyahus answer to your question when you using C# in vb.net
the [] are ()
Dataset1.tblMyTable.Rows[Currentrow] or Dataset1.tblMyTable[Currentrow]

Or in complete dataset now VB.net
Dataset1.tables(0).Rows(Currentrow)

Cor
 
C

Cor Ligthert

Hi Craig,
Doesn't that just refer to the row but does not set the pointer to a row in
the dataset?

As far as I know there is no pointer to a row in a dataset.

In windowforms there is for this the curencymanager, however as far as I
know you cannot use the currencymanager in an webpage.

Otherwise it was in VB something as

Directcast(Bindingcontext(dataset),currencymanager).position = curindex

Cor
 
E

Eliyahu Goldin

That's right. But you don't have to bind to the dataset. You can bind to any
property. So, all you have to do is just to wrap
Dataset1.tables(0).Rows(Currentrow) into a property and use the property
name in the data-binding expression of your textbox.

Eliyahu

Craig said:
Doesn't that just refer to the row but does not set the pointer to a row in
the dataset?


Cor Ligthert said:
Hi Craig

I translate Eliyahus answer to your question when you using C# in vb.net
the [] are ()
Dataset1.tblMyTable.Rows[Currentrow] or Dataset1.tblMyTable[Currentrow]

Or in complete dataset now VB.net
Dataset1.tables(0).Rows(Currentrow)

Cor
 

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