Thursday, August 19, 2010

Facebook's new feature : "Check In"

The social-network giant facebook's new feature "Check in" now allows its mobile users to let their friend know where they are, just by tapping a button.

The company representative Michael Eyal Sharon has written "Starting today, you can immediately tell people about that favorite spot with Facebook Places. You can share where you are and the friends you're with in real time from your mobile device." in the facebook blog

It was announced just yesterday, at Aug 18th, 2010. This feature is not yet being used bu the massive population of facebook users.  Although, the company and its staffs seem to be looking forward to the very positive responses, only time will say, how the people react and how will they adopt this new feature.

Friday, February 19, 2010

Sorting Gridview columns in Asp .NET

I like the gridview control most, to display the data of the database table at the webpage. It has so many features and extensions, which makes programming easier and interesting.

In this article I will show you the method to sort gridview columns. First of all, define the grid view control as follows: (You can have your own colors and formats, but do not forget to mention AllowSorting="True" and mention the function name in onsorting property as onsorting="OnSort” . Onsort is the name of my function, you can have some other name of the function)

<asp:GridView ID="mygrid" runat="server" CellPadding="4" ForeColor="#333333" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"PageSize="15" style="position: static; clear: both; display: block;" onsorting="OnSort">
<asp:BoundField DataField="id" HeaderText="ID" SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />             
<asp:BoundField DataField="address" HeaderText="address" SortExpression="address" />
                   <asp:ButtonField buttontype="Link" commandname="add" Text="Add" />
                   <asp:ButtonField buttontype="Link" commandname="update" Text="Update"  />
                   <asp:ButtonField buttontype="Link" commandname="delete" Text="Delete"  />
              <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
              <FooterStyle BackColor="#990000" ForeColor="White" Font-Bold="True" />
              <PagerStyle ForeColor="#333333" HorizontalAlign="Center" BackColor="#FFCC66" />
              <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
              <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
              <AlternatingRowStyle BackColor="White" />
              <PagerSettings FirstPageText="" LastPageText="" NextPageText=""
                  PreviousPageText="" PageButtonCount="3" Position="Top" />

Now on the code behind page, you need to write functions and property to make the sorting work properly. I wrote the functions and property as follows:

Public Property GridViewSortDirection() As SortDirection
            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 

This property figures the direction out. The default direction is “Ascending”, but if the column is already being sorted once, then it changes to direction to “Descending”.  This way we can sort our columns both in ascending and descending order.
Protected Sub OnSort(ByVal sender As Object, ByVal e As GridViewSortEventArgs) 
        Dim sortExpression As String = e.SortExpression 
        If GridViewSortDirection = SortDirection.Ascending Then 
            GridViewSortDirection = SortDirection.Descending 
            SortGridView(sortExpression, "DESC") 
            GridViewSortDirection = SortDirection.Ascending 
            SortGridView(sortExpression, "ASC") 
        End If 
    End Sub

This is the function which is called at the “onsorting” event of the gridview.

Private Sub SortGridView(ByVal sortExpression As String, ByVal direction As String) 
        Dim SQL As String = "select id, name, address from people"
        Dim da As SqlDataAdapter = New SqlDataAdapter(SQL, MyConnection)
        Dim ds As New DataSet
        da.Fill(ds, "people") 
        Dim dt As DataTable = ds.Tables(0)
        Dim dv As DataView = New DataView(dt) 
        dv.Sort = sortExpression & " " & direction
        mygrid.DataSource = dv
    End Sub
This function binds the gridview again.

In case you are doing something at the rowcommand event of the gridview, this may generate a runtime error. Because, whenever, you click on the gridview column, to sort it, the control goes to the rowcommand event first. To avoid the control trying to execute the code in rowcommand, I did the following:

Protected Sub mygrid_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles mygrid.RowCommand
If (e.CommandArgument <> "id" And e.CommandArgument <> "name" And e.CommandArgument <> "address") Then

‘Do whatever you want to do……………………’

End If
End Sub

In this way, I am able to sort the columns of the gridview.

Wednesday, January 27, 2010

“Apple tablet”: How will it look like?

People are talking about “Apple tablet”. We can see so many news, views, rumors and speculations regarding “Apple tablets” these days. Many designers are sketching their ideas of Apple tablet. I googled “apple tablet” and saw so many pictures about the product which is not even released.
I am wondering what will be the name of the tablet, may be something like iTablet (like iPhone, iPod. People are also saying that the name might be iSlate). This might be the fusion of iPod and iPhone in one, or might be way more powerful and useful than those, or might be just another model of Mac book Pro.
I am also wondering how this highly anticipated gadget will look like. Will it look like one of these? Will it bring a new technological breakthrough or it will be just another gadget? I hope Mr. Jobs announces the new gadget soon, and I will get all my answers. :-)

Tuesday, December 8, 2009


- "I do not fear computers. I fear lack of them". Isaac Asimov

- "Artificial Intelligence usually beats natural stupidity".Author Unknown

- "Physics is the universe’s operating system." Steven R Garman

- "I sit looking at this damn computer screen all day long, day in and day out, week after week, and think: Man, if I could just find the 'on' switch..."  Zachary Good.

- "Hardware:  where the people in your company's software section will tell you the problem is.  Software:  where the people in your company's hardware section will tell you the problem is."  Dave Barry

- "The question of whether computers can think is like the question of whether submarines can swim." Edsger W. Dijkstra

-"The greatest enemy of knowledge is not ignorance, it is the illusion of knowledge."Stephen Hawking

- "Any fool can use a computer.  Many do." Ted Nelson

- "Computing is not about computers any more.  It is about living." Nicholas Negroponte

- "In God we trust, all others we virus scan." Author Unknown


Monday, July 20, 2009

Passing parameters programmatically to Crystal report

It is very easy to pass the parameters in Crystal reports editing the crystal reports ( just by adding the required parameters on the report and making "EnableParameterprompt = "True" " in the properties of the crystal report viewer. , but it has several drawbacks, like the parameters do not get added to the report automatically, we can not really modify the interface of parameter prompt and so on. 

Today we are discussing about the parameter passing to crystal reports programmatically.  
In .aspx page, drag the control to ask for the parameters and drag the control for Crystal report viewer as follows:
<tr><td style="vertical-align: top; text-align: left; height: 21px;"><asp:Label ID="lbl1" runat="server" Text="Choose the semester" style="vertical-align: top; text-align: left" />td>
<td style="height: 21px; vertical-align: top; text-align: left;"><asp:DropDownlist ID="drpSemester" runat="server" AppendDataBoundItems="True" DataSourceID="SqlDataSource1" DataTextField="Semester" DataValueField="Semester"/>td>
tr><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="" SelectCommand="SELECT [Semester] FROM [SemesterInformation] ORDER BY [BeginDate], [EndDate]">
<tr><td><asp:Button ID="cmdGenreport" runat="server" Text="Generate Report" />td>tr>
      <CR:CrystalReportViewer ID="myCrystalReportViewer" runat="server" AutoDataBind="True"
         Height="1039px" ReportSourceID="CrystalReportSource1" Width="901px" style="position: absolute" EnableDatabaseLogonPrompt="false" EnableParameterPrompt="false" />
Design a report with parameters. To add a parameter in a report, you have to go to the “Database expert”, in the command edit box, you will see “parameter list” at the right hand side of the box, create a new parameter there and include that in your query. Add the following code in the load event of your page:
  Dim CRreport As New ReportDocument
        If Session("report1") IsNot Nothing Then
            CRreport = Session("report1")
            myCrystalReportViewer.ReportSource = CRreport
        End If
In the click event if the “cmdgenerateReport” Button add the following code:
  Dim myConnectionInfo As ConnectionInfo = New ConnectionInfo()
        Dim strReportName As String = ""
        Dim cryRep As New ReportDocument
        myConnectionInfo.DatabaseName = "Databasename"
        myConnectionInfo.ServerName = "Servername"
        myConnectionInfo.UserID = "Username"
        myConnectionInfo.Password = "password"
        myConnectionInfo.Type = ConnectionInfoType.SQL
        SetDBLogonForReport(myConnectionInfo, report)
        'Load Session variables with values from web-controls
        Session("Semester") = drpSemester.SelectedValue.ToString()
        'Load all parameter fields associated with the report into "fields" object
        Dim fields As ParameterFields
        fields = New CrystalDecisions.Shared.ParameterFields()
        fields = report.ParameterFields
        For Each field As ParameterField In fields
            report.SetParameterValue(field.Name, Session(field.Name))
        myCrystalReportViewer.ReportSource = report
        Session("report1") = report
The setDBlogonForreport is as follows:
  Private Sub SetDBLogonForReport(ByVal myConnectionInfo As ConnectionInfo, ByVal myReportDocument As ReportDocument)
        Dim myTables As Tables = myReportDocument.Database.Tables
        Dim myTableLogonInfos As TableLogOnInfos = myCrystalReportViewer.LogOnInfo
        Dim myTablelogonInfo As TableLogOnInfo
        For Each myTable As Table In myTables
            myTablelogonInfo = myTable.LogOnInfo
            myTablelogonInfo.ConnectionInfo = myConnectionInfo
    End Sub
To manage the proper navigation of the report include the following code in the .vb page:
  Protected Sub myCrystalReportViewer_Navigate(ByVal source As Object, ByVal e As CrystalDecisions.Web.NavigateEventArgs) Handles myCrystalReportViewer.Navigate
        report.FileName = Server.MapPath("~/myreport1.rpt")
        Dim fields As ParameterFields
        fields = New CrystalDecisions.Shared.ParameterFields()
        fields = report.ParameterFields
    End Sub
Add the following code at the unload event of the page:
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
    End Sub
In this way, you can pass as many parameters as you need to crystal reports.
Please write comment below if you have any kinds of questions/suggestions.