B) السلام عليكم
:)
هذا الكود يقوم بترتيب البيانات في Datagrid باستخدام اكثر من عمود
مثلا ترتيب حسب الاسم تصاعدي ثم حسب العنوان تنازلي
Public Function GetSortCommand(byval _dg As System.Web.UI.WebControls.DataGrid,ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) As String
Dim SortString$ = ""
For Each c As DataGridColumn In _dg.Columns
If c.SortExpression = e.SortExpression Then
If c.HeaderText.EndsWith("</font>") Then c.HeaderText = Left$(c.HeaderText, c.HeaderText.IndexOf("<font")).Trim
If c.SortExpression.EndsWith("ASC") Then
c.SortExpression = c.SortExpression.Replace("ASC", "DESC")
c.HeaderText &= "<font face=Webdings>5</font>"
ElseIf c.SortExpression.EndsWith("DESC") Then
c.SortExpression = c.SortExpression.Replace("DESC", "")
Else
c.SortExpression &= " ASC"
c.HeaderText &= "<font face=Webdings>6</font>"
End If
If c.SortExpression.EndsWith("ASC") Or c.SortExpression.EndsWith("DESC") Then SortString = c.SortExpression & IIf(SortString.Length > 0, ", ", "") & SortString
Else
If c.SortExpression.EndsWith("ASC") Or c.SortExpression.EndsWith("DESC") Then SortString &= IIf(SortString.Length > 0, ", ", "") & c.SortExpression
End If
Next
Return SortString
End Functionالأن في حدث الترتيب داخل Datagrid أضف هذا الكود
Private Sub dgContacts_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles dgContacts.SortCommand dim SortOrder$="" SortOrder= GetSortCommand(dgContacts,e)) End Sub
الان يمكنك أستخدام المتغير SortOrder مع dataView.sort ثم استخدمها في ملئ Datagrid