Close, here's my Sort Proecdure:
Private Sub DataGrid1_SortC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridSortCommand EventArgs) Handles
DataGrid1.SortC ommand
Dim dtParam As DataTable = DsChanges1.Tabl es(0)
dvwParam = dtParam.Default View
dvwParam.Sort = e.SortExpressio n
DataGrid1.DataS ource = dvwParam
DataGrid1.DataB ind()
End Sub
dvwParam is a dataview that binds to the above datatable
(dtparam.defaul tview) as above. So, whenever I actually click on one of the
datagrid1's headhers to sort by that column it sorts just fine, but if I
click on a record, it gives the 'original' value (presorted record) not the
now-sorted-value (record).
The sub that's called when I click on a record is:
Private Sub DataGrid1_EditC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles
DataGrid1.EditC ommand
'This should be the value of the cell(1) a.k.a. Primary key value
"Change_ID" in the datagrid
propChange_ID = CType(e.Item.Ce lls(1).Text, String)
'Pass this ID to the Details form
Server.Transfer ("frmChange_Det ails.aspx")
End Sub
I hope this makes sense. It looks like although the dataview is getting
sorted (which makes it appear the datagrid is sorted as well) the underlying
data table (or whatever is underlying to a dataview/grid) isn't being sorted
which is what my 'DataGrid1_Edit Command' is pointing to.
"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:eI******** ******@TK2MSFTN GP12.phx.gbl...
I'm assuming you are doing something like this....
yourObj.View.So rt = this.dataGrid1. SortOrder;
this.dataGrid1. DataKeyField = "PrimaryKeyFiel dName";
this.dataGrid1. DataSource = yourObj.View;
this.dataGrid1. DataBind();
?
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Jason" <ja***@grossman s.net> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. . Thanks for the reply Curt.
I've set a DataKeyField in the binding but when I click on a datagrid
item after a sort it still returns the wrong value. Does it matter that I'm
sorting using a dataview of the datagrid?
"Curt_C [MVP]" <software_AT_da rkfalz.com> wrote in message
news:ue******** ******@tk2msftn gp13.phx.gbl... make sure to set a DataKeyField in the binding, then use
myValue = dataGrid1.DataK eys[this.dataGrid1. SelectedIndex].ToString();
--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com
"Jason" <ja***@grossman s.net> wrote in message
news:%2******** ********@tk2msf tngp13.phx.gbl. ..
> I've been trying to figure out a good way to do this but haven't had
much > luck, any input would be greatly appreciated.
>
> Basically, after a datagrid is sorted, how can I get the primary key
value > of the item selected by the user? That is, not the datagrid index
> 'location' of the item the user selected, but the value inside a
column of > this item the user clicked on.
>
> I would use the CurrencyManager in a windows application but I'm not
sure > what to use in a web form.
>
> Thanks in advance,
>
> Jason
>
>