Tuesday, November 25, 2008

Quotes?

“Before software should be reusable, it should be usable.”– Ralph Johnson

“Commenting your code is like cleaning your bathroom — you never want to do it, but it really does create a more pleasant experience for you and your guests.”– Ryan Campbell

“Passwords are like underwear: you don’t let people see it, you should change it very often, and you shouldn’t share it with strangers.”– Chris Pirillo

“It is easier to change the specification to fit the program than vice versa.”– Alan Perlis

“The computer was born to solve problems that did not exist before.”– Bill Gates

“The more you know, the more you realize you know nothing.”– Socrates

What is an astronaut's favorite key on a computer keyboard? The space bar.

Computer dating is fine, if you're a computer.

Friday, May 2, 2008

Removing items from dropdownlist.

The following will remove nothing:

this.DropDownList1.Items.Remove("Manchester"); //Text

this.DropDownList1.Items.Remove("201"); //Value

Remove() works by first constructing a new ListItem from the specified string, and then removing the specified ListItem. In other words, Remove item works as below:

this.DropDownList1.Items.Remove(new ListItem("Manchester"));

Tuesday, April 29, 2008

Deploying custom assembly in SSRS.

Follow these simple steps to create and deploy custom assembly inorder to access in reports.

I will take you through a simple example where you wanted to override colors for bars inthe chart.

1) Create a Class library called ReportStyle.

2) Define a function called GetColor() which returns color.

[ This function could read predefined colors from database or from web.config file. ]

3) Compile the ClassLibrary. Pick the dll from bin folder and place it in the following path to reuse it across applications.

-----------------------------------------------------------------------------

C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PrivateAssemblies

--------------------------------------------------------------------------------

4) Now Right click on report designer. Go to report properties, Reference tab.

5) Under References, Browse for the Assembly ReportStyle.dll and add.

6) Under Classes, provide the class name and instance name.(Important point :provide full class name)

7) Go to Chart Properties, DataTab.

8) Go to appearance tab for chart values and provide the code to set color programatically as below =Code.obj.GetColor(!fieldvalue)

9) Inorder to access it from report server, place the same dll in the following installed path: C:\Program Files\Microsoft SQL Server\MSSQL.3\Reporting Services\ReportServer\bin

10) Bydefault full trust is not given to the dll.

Therefore go to rssrvpolicy.config and provide the class name or open the web.config and edit node as follows:

[ Other alternative is to enable it through CAS in .Net ] Thats it and u r done.

Wednesday, April 9, 2008

Looping through Gridview rows.

Consider a scenario where you want to delete all the selected records in the gridview.

First of all , a primary key has to be set for each record which can be done by declaratively setting datakeynames property in the gridview tag.

Loop through the GridViewRows as shown in the code snippet below:

CheckBox chk = null;

StringBuilder sweepStakeIds = new StringBuilder();

int index = 0;

foreach (GridViewRow row in grdSweepStakes.Rows)

{

chk = (CheckBox)row.FindControl("chkSelect");

if (chk.Checked)

{

sweepStakeIds.Append(grdSweepStakes.DataKeys[index].Value.ToString());

sweepStakeIds.Append(",");

index++;

} Here ids are passed as comma separated values to stored procedured where it is taken care by the logic inside the procedureinorder to reduce database talk by deleting all the records in one go.