Sunday, October 10, 2010

ReportViewer.exe 2010 Distributable

You can download reportviewer.exe 2010 download using the link given below.

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=A941C6B2-64DD-4D03-9CA7-4017A0D164FD&displaylang=en

Wednesday, May 5, 2010

ASP.NET : Change forecolor based on backcolor

One of the applications we were developing in asp.net needed use of random background colors for table cells. This was easy in vb.net
Just create an array of allcolors like this :

   Dim allColors As String()
Now populate the array using this :
   allColors = [Enum].GetNames(GetType(System.Drawing.KnownColor))

and then use this array for randomly coloring the cell backcolor.

However, a new problem arose. It was found that if the forecolor is retained as black and the backcolor is a dark color, cell text is not readable.  This can be handled by using the cell.backcolor.getBrightness property. Change the forecolor to white if brightness is less than 0.5 otherwise retain forecolor as black.

Thursday, January 14, 2010

Multiple column sort of a gridview in asp.net

Most commercial applications require sorting to be integral to any gridview. You can implement multiple column sort using these instructions.


1. Add a gridview to the aspx file.

An image has been added as blog security features do not display the above code properly.

2. Include a proceudre to bind data to the gridview.

Protected Sub BindGrid()
Dim x As New Business.Employees
Dim tb As New DataTable
tb = x.GetTestTable.Tables(0)
Dim dv As DataView
dv = tb.DefaultView
If Not (GridView1.Attributes("SortExpression") Is Nothing) Then
dv.Sort = GridView1.Attributes("SortExpression")
End If
GridView1.DataSource = dv
GridView1.DataBind()
End Sub


3. Include a procedure to be called when the user clicks on the column header


Private Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim s As String
'Get existing sort expression
s = GridView1.Attributes("SortExpression")

'If the column has been included
If InStr(s, e.SortExpression.ToString()) > 0 Then
'If the column has been sorted in descending order, we remove the column from the sort expression
If InStr(s, e.SortExpression.ToString() & " DESC") > 0 Then
s = s.Replace(e.SortExpression.ToString() & " DESC", "")
s = LTrim(RTrim(s))
If s.IndexOf(",") = 0 Then
s = s.Remove(0, 1)
End If
If s.LastIndexOf(",") = (s.Length - 1) And s.Length > 0 Then
s = s.Remove(s.Length - 1, 1)
End If
s = s.Replace(",,", ",")
Else
'If the column has been sorted in ascending order, we change it to descending order
s = s.Replace(e.SortExpression.ToString(), e.SortExpression.ToString() & " DESC")
End If
Else
'If the column has not been included
If s Is Nothing Then
s = e.SortExpression.ToString()
Else
If s.Length = 0 Then
s = e.SortExpression.ToString()
Else
'If another column already exists then include the new column retaining the earlier one
s = s & "," & e.SortExpression.ToString()
End If
End If
End If
GridView1.Attributes("SortExpression") = s
BindGrid()
End Sub

4. Include a procedure to change the header based on sorting information.


Private Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

If e.Row.RowType.ToString = "Header" Then
Dim i As Integer
Dim s As String
Dim lb As LinkButton
Dim img As Image
Dim sSort As String
sSort = GridView1.Attributes("SortExpression")
i = 0
While i <>
lb = e.Row.Cells(i).Controls(0)
s = lb.Text
'Insert image in cell if sorted on this field
If InStr(sSort, s) > 0 Then
img = New Image
If InStr(sSort, s & " DESC") > 0 Then
img.ImageUrl = "images/desc.png"
Else
img.ImageUrl = "images/asc.png"
End If
e.Row.Cells(i).Controls.Add(img)
End If
i = i + 1
End While
End If
End Sub

4. Obviously, you will need to call BindGrid on page load.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsCallback Then
BindGrid()
End If
End Sub

5. When you run the form, depending on the data that is available in dt, you could get the following output.

Tuesday, December 25, 2007

Unable to execute aspx file on Windows 2003

Had problems executing aspx files on Windows 2003. The machine already had Windows 2003 SP2, Dot Net 1.1 and IIS installed but refused to serve aspx files although html files were being processed. Kept getting this error "Error 404 - File not found" every time an aspx file was requested.

Installing Dot Net 2.0 also did not solve the problem.

In IIS found that the Web Service Extension node allows you to prohibit execution of certain types of files. For some reason ASP.NET v1.1 and v2.0 were prohibited. Changing the status to Allow solved the problem.

Saturday, December 15, 2007

SQL Server 2005 - No Process is on the Other End of the Pipe

Had some problem connecting to SQL Server 2005 using SQL Server Authentication. Kept getting the error "No Process is on the Other End of the Pipe".

Found a solution in the following page
click here

1. Start SQL Server Surface Area Configuration Manager.
2. Click on Surface Area Configuration for Services and Connections.
3. Expand the Database Engine node.
4. Click on Remote Connections
5. Ensure that "Local and Remote Connections" is selected and also ensure that "Using both TCP/IP and named pipes" are selected.