Thursday, April 7, 2011

Reporting Service - Designing a Report From Scratch

Try It!

To create a fresh report in Report Designer, follow these steps:

  1. Select File > New > Project.
  2. Select the Business Intelligence Projects project type.
  3. Select the Report Server Project template.
  4. Name the new report ProductReport2 and pick a convenient location to save it in.
  5. Right-click on the Reports node in Solution Explorer and select Add > New Item.
  6. Select the Report template.
  7. Name the new report ProductReport2.rdl and click Add.
  8. In the Report Data window, select New > Data Source.
  9. Name the new Data Source AdventureWorksDS.
  10. Select the Embedded Connection option and click on the Edit button.
  11. Connect to your test server and choose the AdventureWorks2008 database.
  12. Click OK.
  13. Click OK again to create the data source.
  14. In the Report Data window, select New > Dataset.
  15. Name the dataset dsLocation.
  16. Click the Query Designer button.
  17. If the full Query Designer does not appear, click on the Edit As Text button.
  18. Click the Add Table button.
  19. Select the Location table.
  20. Click Add.
  21. Click Close.
  22. Check the boxes for the Name and CostRate columns.
  23. Sort the dataset in ascending order by Name and click OK.
  24. Click OK again to create the dataset.
  25. Open the toolbox window (View > Toolbox).
  26. Double-click the Table control.
  27. Switch back to the Report Data window.
  28. Expand the dataset to show the column names.
  29. Drag the Name field and drop it in the first column of the table control on the design tab.
  30. Drag the CostRate field from the Report Data window and drop it in the second column of the table control.
  31. Place the cursor between the column selectors above the Name and CostRate columns to display a double-headed arrow. Hold down the mouse button and drag the cursor to the right to widen the Name column.
  32. Figure 17-6 shows the report in Design view.

    Figure 17-6: Designing a report from scratch

    Figure 17-6: Designing a report from scratch

  33. Select the Preview tab to see the report with data.

Friday, March 11, 2011

SQL Server Restore Database Failed - Because the database is in use.

Force to close all existing connection

use master
go
alter database DatabaseName set single_user with rollback immediate
alter database DatabaseName set multi_user

Thursday, January 20, 2011

ASP.NET: Hide AutoGenerateColumns in GridView Programmatically

Option 1: Using the Cells index

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//Just changed the index of cells based on your requirements
e.Row.Cells[0].Visible = false;

}


Option 2: Looping through GridView Row Controls collections

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//Just changed the index of cells based on your requirements
foreach (TableRow row in GridView1.Controls[0].Controls)
{
row.Cells[0].Visible = false;
}

}

You can use the above options for hiding the columns if you are sure with the order of the columns in the Table. Please note that autogenerated columns will display all the columns from the DataSource, so you must be careful when using index for hiding the columns.


Option 3: Looping through GridView Cells

As you may know the GridView cells are composed of different DataControlFields and basically AutoGenerated fields uses a BoundField for displaying the data. In this case we can loop through the cells generated by the GridView and cast the cell to a DataControlFieldCell type to get the ContainingField then we can cast this ContainingField to a BoundField sothat we can check the DataField used in a particular AutoGenerated BoundField and Hide them using its visible property.

To make it more clearer then you can check this code block below:

protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//Just set the Column Name that you wish to hide based on your requirements
foreach (TableCell cell in e.Row.Cells)
{
BoundField field = (BoundField)((DataControlFieldCell)cell).ContainingField;
if (field.DataField == "ColumnName")
{
field.Visible = false;
}
}

}