adding more information

A

ashelley

Hello,

If i am binding a datagrid to a dataset, is there anyway to include
each rows index number so that I can explicly reference it on the
itemdatabound event regardless of sort order / filtering.

Here's what I want to do for my ItemDataBound event.

//xd is a XmlDataDocument that has been stored in a session

xd.DataSet.Tables["PART"].Rows[int.Parse(e.Item.Cells[0].Text)].GetChildRows("PART_DET");

where

e.Item.Cells[0].Text is the original row number as found in the
dataset?

-Adam
 
E

Eliyahu Goldin

Hello,

If i am binding a datagrid to a dataset, is there anyway to include
each rows index number so that I can explicly reference it on the
itemdatabound event regardless of sort order / filtering.

Here's what I want to do for my ItemDataBound event.

//xd is a XmlDataDocument that has been stored in a session

xd.DataSet.Tables["PART"].Rows[int.Parse(e.Item.Cells[0].Text)].GetChildRows
("PART_DET");

where

e.Item.Cells[0].Text is the original row number as found in the
dataset?

-Adam
 
E

Eliyahu Goldin

Adam,

You can add a column to the grid, populate it with row indexes on the first
itemdatabound event and make it invisible.

Eliyahu
 
A

ashelley

is it a function of the dataset to provide the row index to the
datagrid in a bound column?

what is this call?

ie <asp:boundcolumn datasource="rowindex()"/>?

-Adam
 
A

ashelley

then if the dataset is filtered or sorted then the row index will be
incorrect.

-Adam
 
E

Eliyahu Goldin

No, just count the rows yourself in ItemDataBound event. Don't forget to
ignore non-datarow items, like header.

Eliyahu
 
A

ashelley

Adam,

You are right. I understood that you first show the full table and than
sorting or filtering is applied. Apparently it is not the case. You can't
use row index simply because it is not something absolute and there is no
such a property. You should use table's primary key instead.

Eliyahu

What if there are a couple of thousand records in the dataset? Would
using primary key be efficient _enough_ in this case?

The only option I can think of is when generating the dataset make a
primary key as an integer so that the index in the dataset is directly
correlated to the primary key,

but is this the only way?

-Adam
 
E

Eliyahu Goldin

Adam,

You are right. I understood that you first show the full table and than
sorting or filtering is applied. Apparently it is not the case. You can't
use row index simply because it is not something absolute and there is no
such a property. You should use table's primary key instead.

Eliyahu
 

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

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,540
Members
45,025
Latest member
KetoRushACVFitness

Latest Threads

Top