Datagrid / Dataview Help On Select after SORT...

G

Guest

I have a datagrid that I am using a DataView with. All works great for the
sorting of the columns. However, after I sort the column, and then try and
select a data row to edit, the row selected represents the indes of the
actual DataGrid and not the DataView. For example.. Lets say I have 4 rows
of data.. In the 4 rows I have an Appt Num of 1,2,3,4... Each representing
a data row... I sort DESC so the rows display 4,3,2,1... If I select the
2ND row of data, I will see #2 rather Than #3 as I should since the data view
is sorted DESC... PLEASE HELP.. I am sure it is something I am
overlooking... Thanks.. Bruce
 
S

Scott M.

What you need to do is "locate" the currently selected row in the DataSet
like this:

[VB.NET]

Dim theDataSetRow As DataRow = ds.Tables(0).Select("FieldName ='" &
CType(e.Item.FindControl("controlNameThatWouldHaveTheDataInIt"),
controlType).Text & "'")(0)
 
G

Guest

Scott, I apologize for my ignorance... However, I am having a hard time with
this code. I have it in the correct place, however, not sure I am using it
correctly..

For the FIELDNAME I have used APPTNO because that is the heading of the
field in the table I would be looking for.. I am not sure what to use for
the e.Item.FindControl("controlNameThatWouldHaveTheDataInIt"),

Again, I appreciate your help and apologize.... Any additional help will
be appreciated...

Thanks... Bruce

Scott M. said:
What you need to do is "locate" the currently selected row in the DataSet
like this:

[VB.NET]

Dim theDataSetRow As DataRow = ds.Tables(0).Select("FieldName ='" &
CType(e.Item.FindControl("controlNameThatWouldHaveTheDataInIt"),
controlType).Text & "'")(0)



Bruce Pullum said:
I have a datagrid that I am using a DataView with. All works great for the
sorting of the columns. However, after I sort the column, and then try
and
select a data row to edit, the row selected represents the indes of the
actual DataGrid and not the DataView. For example.. Lets say I have 4
rows
of data.. In the 4 rows I have an Appt Num of 1,2,3,4... Each
representing
a data row... I sort DESC so the rows display 4,3,2,1... If I select the
2ND row of data, I will see #2 rather Than #3 as I should since the data
view
is sorted DESC... PLEASE HELP.. I am sure it is something I am
overlooking... Thanks.. Bruce
 
S

Scott M.

e.Item refers to the "row" of the DataGrid that you are working on. Within
that row, you most likely have more than one column, so to be searching the
rows of the grid by a particular field name, you need to find the control in
that row that is supposed to be holding the field data you are looking for
(APPTNO in your case).

When a grid renders its rows, it places its data directly into the cell of
the table (ultimately rendered as a <TD> tag). That makes it difficult to
track down particular cells, so you should manually create columns for your
DataGrid (via the PropertyBuilder dialog of the grid). Start by creating
Bound columns and then click the "Convert to Template column" hyperlink to
make this column a Template column. From there, you can place controls of
your choosing into each column (and most importantly, you can now give that
control an ID of your choosing).

When I say "controlNameThatWouldHaveTheDataInIt", I mean the name of the
control I just mentioned.

I know this sounds confusing and it certainly can be, but to build a good
DataGrid that offers the editing, selecting, sorting, paging capabilities
you seek, it takes a bit of work.

Check out
http://msdn.microsoft.com/library/d...kaddingtemplatecolumntodatagridwebcontrol.asp
for more details on Template Columns.

-Scott

Bruce Pullum said:
Scott, I apologize for my ignorance... However, I am having a hard time
with
this code. I have it in the correct place, however, not sure I am using
it
correctly..

For the FIELDNAME I have used APPTNO because that is the heading of the
field in the table I would be looking for.. I am not sure what to use for
the e.Item.FindControl("controlNameThatWouldHaveTheDataInIt"),

Again, I appreciate your help and apologize.... Any additional help will
be appreciated...

Thanks... Bruce

Scott M. said:
What you need to do is "locate" the currently selected row in the DataSet
like this:

[VB.NET]

Dim theDataSetRow As DataRow = ds.Tables(0).Select("FieldName ='" &
CType(e.Item.FindControl("controlNameThatWouldHaveTheDataInIt"),
controlType).Text & "'")(0)



Bruce Pullum said:
I have a datagrid that I am using a DataView with. All works great for
the
sorting of the columns. However, after I sort the column, and then try
and
select a data row to edit, the row selected represents the indes of the
actual DataGrid and not the DataView. For example.. Lets say I have
4
rows
of data.. In the 4 rows I have an Appt Num of 1,2,3,4... Each
representing
a data row... I sort DESC so the rows display 4,3,2,1... If I select
the
2ND row of data, I will see #2 rather Than #3 as I should since the
data
view
is sorted DESC... PLEASE HELP.. I am sure it is something I am
overlooking... Thanks.. Bruce
 

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