How do you sort the data in datagrid?
Answers were Sorted based on User's Feedback
Answer / murty
By setting "allow sorting" property of the datagrid to
true we can sort the records in the data grid
| Is This Answer Correct ? | 3 Yes | 1 No |
Answer / shiva
Protected Sub Sorting(ByVal sender As Object, ByVal e As
GridViewSortEventArgs)
Dim DESCENDING As String = "DESC"
Dim ASCENDING As String = "ASC"
Dim sortExpression As String = e.SortExpression
If GridViewSortDirection = SortDirection.Ascending
Then
GridViewSortDirection = SortDirection.Descending
SortGridView(sortExpression, DESCENDING)
Else
GridViewSortDirection = SortDirection.Ascending
SortGridView(sortExpression, ASCENDING)
End If
End Sub
(Call this onsorting in datagrdi)
2)
Public Property GridViewSortDirection() As SortDirection
Get
If ViewState("sortDirection") Is Nothing Then
ViewState("sortDirection") =
SortDirection.Ascending
End If
Return CType(ViewState("sortDirection"),
SortDirection)
End Get
Set(ByVal value As SortDirection)
ViewState("sortDirection") = value
End Set
End Property
3) Private Sub SortGridView(ByVal sortExpression As String,
ByVal direction As String)
Try
Dim dt As DataTable = BindData().Tables(0)
Dim dv As New DataView(dt)
dv.Sort = sortExpression + " " + direction
gdvCamp.DataSource = dv
gdvCamp.PageIndex = 0
gdvCamp.DataBind()
Catch ex As Exception
Response.Write(ex.Message)
End Try
End Sub 'SortGridView
Bing the data like fallows
Private Function BindData() As DataSet
Binding Goes here which should returns dataset to above
function
End FUnction
| Is This Answer Correct ? | 1 Yes | 0 No |
datagrid has a property for sorting and paging
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / sunil
In a simple method,
DataSet ds = new DataSet();
// you must populate the dataset
DataTable dt = ds.tables[0];
DataView dv = new DataView(dt);
dv.Sort = dt.Columns[0];
// This will sort first column in ascending
dv.Sort = dt.Columns[0] + " DESC";
// This will sort first column in descending
| Is This Answer Correct ? | 1 Yes | 3 No |
How would you connect to a database by using .NET?
What is the difference between ADO and ADO.Net?
Which method in OLEDBAdapter is used to populate dataset with records?
What are the advantages of using datalist?
Can we do database operations without using any of the ado.net objects?
Which is better entity framework or ado.net?
What are the steps you will take to improve performance?
Execute nonquery returns no. of afected rows.So if my stored procedure hav lot of select stmnt, delete stmnt, insert stmnt..then what does execute nonquery returns in this case?
When multiple users attempt to modify data at the same time Ex user 1 is updating record at same time user2 deleted record sucessfully.now user1 has press update button . how to handle concurrency
What do you know about ado.net's methods?
Why DataReader is Forward Only?
Explain what a diffgram is and its usage ?
Visual Basic (800)
C Sharp (3816)
ASP.NET (3180)
VB.NET (461)
COM+ (79)
ADO.NET (717)
IIS (369)
MTS (11)
Crystal Reports (81)
BizTalk (89)
Dot Net (2435)
Exchange Server (362)
SharePoint (720)
WCF (340)
MS Office Microsoft (6963)
LINQ Language-Integrated Query (317)
WPF (371)
TypeScript (144)
Microsoft Related AllOther (311)