Home All Groups Group Topic Archive Search About

DataTable -> DataView -> Sort -> DataGrid : need related DataTable index

Author
26 Jun 2006 7:25 PM
Diamonds
Hello,

In my DataGrid for ASP.NET C#,

In the UI the user adds rows to the DataGrid and the values are saved
in a DataTable.

The DataTable is displayed by using a DataView. The DataView is sorted
then bound to the DataGrid.

The DataGrid allows editing. It knows which row to change based on
Item.ItemIndex. However, it is using the ItemIndex of the DataView. I
need to map the DataView index to the DataTable index to edit the
correct row.

The sort is = "Col1, Col2 ASC".


Am I doing this correctly?
How would I get the related DataTable row?

Author
26 Jun 2006 10:00 PM
Diamonds
I came up with a solution but it seems that I am doing it wrong.

My DataTable now has a column called "PK" for primary key which it
increments on its own each time a value is added. In the DataGrid I
have a hidden Column which has a label with a text value of the PK
value.

On a delete the following code is executed:

Label PK = (Label) e.Item.FindControl("PK");
DataRow[] dr = Seats.Select("[Primary Key] = '"+PK.Text+"'");
if (dr.Length > 0)
    Seats.Rows.Remove(dr[0]);

Please let me know if there is a more elegant solution to this. Perhaps
assigning the PK value the correlated DataTable index, instead of a
textual representation that I have to 'Select'.

Cheers,

Diamonds wrote:
Show quote
> Hello,
>
> In my DataGrid for ASP.NET C#,
>
> In the UI the user adds rows to the DataGrid and the values are saved
> in a DataTable.
>
> The DataTable is displayed by using a DataView. The DataView is sorted
> then bound to the DataGrid.
>
> The DataGrid allows editing. It knows which row to change based on
> Item.ItemIndex. However, it is using the ItemIndex of the DataView. I
> need to map the DataView index to the DataTable index to edit the
> correct row.
>
> The sort is = "Col1, Col2 ASC".
>
>
> Am I doing this correctly?
> How would I get the related DataTable row?
Author
27 Jun 2006 6:32 AM
Cor Ligthert [MVP]
Diamonds,

To get datarow from the current datarowview (the rows from a dataview) is
very simple.

dr = drv.Row;

I hope this helps,

Cor

Show quote
"Diamonds" <cwstew***@gmail.com> schreef in bericht
news:1151349912.467505.58450@m73g2000cwd.googlegroups.com...
> Hello,
>
> In my DataGrid for ASP.NET C#,
>
> In the UI the user adds rows to the DataGrid and the values are saved
> in a DataTable.
>
> The DataTable is displayed by using a DataView. The DataView is sorted
> then bound to the DataGrid.
>
> The DataGrid allows editing. It knows which row to change based on
> Item.ItemIndex. However, it is using the ItemIndex of the DataView. I
> need to map the DataView index to the DataTable index to edit the
> correct row.
>
> The sort is = "Col1, Col2 ASC".
>
>
> Am I doing this correctly?
> How would I get the related DataTable row?
>
Author
28 Jun 2006 5:42 PM
Diamonds
So I could use dr to .Remove() from the datatable?
Even though the datarow came from the view, they are still the same
reference?

Thnx for your help. I'm really worreid that I'm doing this the long
way.

Cheers,

Cor Ligthert [MVP] wrote:
Show quote
> Diamonds,
>
> To get datarow from the current datarowview (the rows from a dataview) is
> very simple.
>
> dr = drv.Row;
>
> I hope this helps,
>
> Cor
>
> "Diamonds" <cwstew***@gmail.com> schreef in bericht
> news:1151349912.467505.58450@m73g2000cwd.googlegroups.com...
> > Hello,
> >
> > In my DataGrid for ASP.NET C#,
> >
> > In the UI the user adds rows to the DataGrid and the values are saved
> > in a DataTable.
> >
> > The DataTable is displayed by using a DataView. The DataView is sorted
> > then bound to the DataGrid.
> >
> > The DataGrid allows editing. It knows which row to change based on
> > Item.ItemIndex. However, it is using the ItemIndex of the DataView. I
> > need to map the DataView index to the DataTable index to edit the
> > correct row.
> >
> > The sort is = "Col1, Col2 ASC".
> >
> >
> > Am I doing this correctly?
> > How would I get the related DataTable row?
> >
Author
28 Jun 2006 7:23 PM
Cor Ligthert [MVP]
Diamonds,

This you did not ask. But don't use the remove if you wants to update a
database later.

A "remove" removes a row from a datatable, so the update does not know
anything anymore from that row.

A "delete" set a rowstate, so that the update can use that to delete the row
from the database.

(This rowstate is not set as the row was new inserted).

The rowstates are cleaned and the rows really removed by the dataset or by
the command. Datatable.acceptchanges.

I hope this helps,

Cor

Show quote
"Diamonds" <cwstew***@gmail.com> schreef in bericht
news:1151516549.485639.107680@i40g2000cwc.googlegroups.com...
> So I could use dr to .Remove() from the datatable?
> Even though the datarow came from the view, they are still the same
> reference?
>
> Thnx for your help. I'm really worreid that I'm doing this the long
> way.
>
> Cheers,
>
> Cor Ligthert [MVP] wrote:
>> Diamonds,
>>
>> To get datarow from the current datarowview (the rows from a dataview) is
>> very simple.
>>
>> dr = drv.Row;
>>
>> I hope this helps,
>>
>> Cor
>>
>> "Diamonds" <cwstew***@gmail.com> schreef in bericht
>> news:1151349912.467505.58450@m73g2000cwd.googlegroups.com...
>> > Hello,
>> >
>> > In my DataGrid for ASP.NET C#,
>> >
>> > In the UI the user adds rows to the DataGrid and the values are saved
>> > in a DataTable.
>> >
>> > The DataTable is displayed by using a DataView. The DataView is sorted
>> > then bound to the DataGrid.
>> >
>> > The DataGrid allows editing. It knows which row to change based on
>> > Item.ItemIndex. However, it is using the ItemIndex of the DataView. I
>> > need to map the DataView index to the DataTable index to edit the
>> > correct row.
>> >
>> > The sort is = "Col1, Col2 ASC".
>> >
>> >
>> > Am I doing this correctly?
>> > How would I get the related DataTable row?
>> >
>

AddThis Social Bookmark Button