Sort a GridView Column related to other Table
Posted
by Tim
on Stack Overflow
See other posts from Stack Overflow
or by Tim
Published on 2010-06-10T11:02:00Z
Indexed on
2010/06/10
11:12 UTC
Read the original article
Hit count: 253
Hello,
i have a GridView bound to a DataView. Some columns in the DataView's table are foreignkeys to related tables(f.e. Customer). I want to enable sorting for these columns too, but all i can do is sorting the foreignkey(fiCustomer) and not the CustomerName.
I have tried this without success(" Cannot find column ERP_Customer.CustomerName "):
<asp:TemplateField HeaderText="Customer" SortExpression="ERP_Customer.CustomerName" >
A tried also the DataViewManager, but i've a problem to detect the table to sort:
Dim viewManager As New DataViewManager(Me.dsERP)
viewManager.DataViewSettings(dsERP.ERP_Charge).RowFilter = filter
viewManager.DataViewSettings(dsERP.ERP_Charge).Sort = sort 'sort is the GridView's SortExpression
Me.GrdCharge.DataSource = viewManager.CreateDataView(dsERP.ERP_Charge)
I have to apply the sort on a distinct table of the DataViewManager, but this table would differ on the related tables. I have bound the TemplateColumns in Codebehind in RowDataBound-Event f.e.:
Dim LblCustomer As Label = DirectCast(e.Row.FindControl("LblCustomer"), Label)
LblCustomer.Text = drCharge.ERP_CustomerRow.CustomerName 'drCharge inherits DataRow
What is the recommended way to sort a GridView on columns related to another table?
© Stack Overflow or respective owner