|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
DataTable -> DataView -> Sort -> DataGrid : need related DataTable indexIn 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? 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 quoteHide 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? 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 quoteHide 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? > 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 quoteHide 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? > > 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 quoteHide 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? >> > >
Other interesting topics
Simple Query Notification - Doesn't Work!!
Retrieve GUID on/after insert? refreshing datasets Error during postback of web page related to SqlClient.SqlParamete ExecuteReader question GridView not showing inserted record Troubles connecting with VMWare? Error: The SqlDbType enumeration value, 4, is invalid. Bussiness logic code How can i change varchar to datetime |
|||||||||||||||||||||||