Friday, November 29, 2013

Sort Column data in GridView with Entity Framework

 Using db As New Model.ApplicationEntities()

            Dim q = From tm In db.lk_xyzEnitty
                           .... .... .. .....
                    Select ..... ...... ..

            ' Logic to sort the resultant list based on sort expression
            If Not ResourceSortExpression Is Nothing AndAlso ResourceSortExpression <> String.Empty Then
                ' From grid, if click on sort link then below logic applied
                Dim param = Expression.Parameter(GetType(lk_xyzEnitty), CStr(ResourceSortExpression))
                Dim sortExpression = Expression.Lambda(Of Func(Of lk_xyzEnitty, Object))(Expression.Convert(Expression.Property(param, ResourceSortExpression), GetType(Object)), param)

                If ResourceSortDirection = "ASC" Then
                    gridViewControl.DataSource = q.ToList().AsQueryable().OrderBy(sortExpression)
                Else
                    gridViewControl.DataSource = q.ToList().AsQueryable().OrderByDescending(sortExpression)
                End If
            Else
                ' By default or First time, resources order by Name
                gridViewControl.DataSource = q.ToList()
            End If

            gridViewControl.DataBind()

        End Using

NoteResourceSortExpression is property. 
ResourceSortExpression = e.SortExpression from gridViewControl_Sorting event handler.

Wednesday, November 13, 2013

TSQL - Filter/Show All or specific records from Select query

-- Trick to filter/show all or specific records from select query 
DECLARE @AllRecords NCHAR(1) 

IF (@RoleID <= 0) 
SET @AllRecords = N'Y' 
ELSE 
SET @AllRecords = N'N' 

SELECT 
ROW_NUMBER() OVER (ORDER BY ar.RoleId) AS RowID , 
RoleName, 
.... 

FROM 
table1 
... 
.. 
. 
WHERE 
ar.RoleID = @RoleID OR @AllRecords = N'Y' 
... 
.. 
. 

Thursday, November 7, 2013

Nenu naa pychayam :P

1. Beach nunchi sunrise and sunsent chooste fantastic ga vuntundi.. ade ammaitho chooste manchi Romantic ga vuntundi.
-------------------------------------
2. Samarayogulnni (freedom fighters) sanmanichukoleka pothunnam..Kanisam smarinchukundham.
-------------------------------
3. Eakathvam le ni naayakathvam..
---------------------------
4. Raastram ragili potundhi.. kaastam ga kaali potundhi..
Veetini aape vare lera??

Avunu le.. kaastanni madhylo aarapakoodadhu ga.. andhukanenemo mari :p
----------------------------------------
4. Thappu ga chese prabhutvam vundi..
Thappu ani cheppe prathi paksham vundi..
kani padhavi loki vachhi manchi chese valle karvu iyyaru...

Eppudu topic Samakyndhra, telangana kaadhu.. Pavan kalyan politics loki vastada ani.. Media kooda super kada :) VAllaki TRP ratings ravali ga :p
----------------------------------------------

5. Nirbandhamyna prema..Sunnitha veta anivi vundavu.. 
Ante balavanthamyna prema anedi vundadhu..swachhandham ga ne premistham.

----------------------
Pure Telugu Words:
Dhohithrudu - koothuru bidda