17 April 2012

MS Chart Legend Properties and Hide Series Based on Condition

I have a MSChart that displays two series. The data is taken from a database. Sometimes I only want to display one of the series in my chart based on the condition. Follow the bellow steps to hide series.
                 Chart1.Series["Series Name"].Enabled = false; 


We can set Legends properties in code behind as shown bellow steps.
                Chart1.Legends["Default"].Title = "Chart";
                Chart1.Legends["Default"].LegendStyle = LegendStyle.Column;
                Chart1.Legends["Default"].Docking = LegendDocking.Right;
                Chart1.Legends["Default"].Alignment = StringAlignment.Center;
                Chart1.Legends["Default"].BackColor = System.Drawing.Color.Transparent;
                Chart1.Legends["Default"].IsTextAutoFit = false;
                Chart1.Legends["Default"].BorderColor = Color.Black;
                Chart1.Legends["Default"].BorderWidth = 2;
                Chart1.Legends["Default"].BorderDashStyle = ChartDashStyle.Solid;
                Chart1.Legends["Default"].Font = new Font("Arial", 10, FontStyle.Bold);
                Chart1.Legends["Default"].ForeColor = Color.Black;
                Chart1.Legends["Default"].IsEquallySpacedItems = true;


We can set Legends properties in Design 

<Legends>
     <asp:Legend Name="Legend1" Docking="Right" Title="Chart" ForeColor="Black" BorderColor="Black" BorderWidth="2"  BorderDashStyle="Solid" BackColor="Transparent" Font="Trebuchet MS, 8.25pt, style=Bold"  IsTextAutoFit="False">
     </asp:Legend>
</Legends>

05 April 2012

Comparing ListView with GridView,DataList and Repeater

ASP.NET 3.5 introduces a new data binding control named the ListView. ASP.NET already has a lot of data bind controls; it should be more than 10. But the good news is, ListView can literally replace all other data binding controls in ASP.NET. ListView control makes data binding easier than previous controls. It has included styling with CSS, flexible pagination, and sorting, inserting, deleting, and updating features.

  1. A very flexible and customizable layout.
  2. A built in data paging support with the new DataPager control.
  3. Support data grouping (repeating items) in a flexible way.
  4. Built in support for deleting,inserting,paging,sorting,and updating the data.
Now , to compare the ListView control with the dataList,GridView and repeater control , lets look at the table below : 

Supported Funcationalities
ControlPagingData GroupingProvide Flexible LayoutUpdate,DeleteInsertSorting
ListViewsupportedsupportedsupportedsupportedsupportedsupported
GridViewsupportedNot supportedNot SupportedsupportedNot Supportedsupported
DataListNot supportedsupportedsupportedNot supportedNot supportedNot supported
RepeaterNot supportedNot supportedsupportedNot supportedNot supportedNot supported
* Supported: means that it's provided out of the box without any custom code or hacks.
* Not Supported: means that it's not provided out of the box by the control but it could be possible to implement it using custom code \ hacks.
The GridView : it supports paging but it doesn't provide a flexible layout , since its mainly used to display the data in a table based layout.And If we looked at data inserting , the Gridview doesn't have a built in support for inserting data( since it doesn't call the insert method of it underlying data source when you click on a button with a CommadName set to "Insert" ).
The DataList : it support data grouping ( through its RepeatColumns property) , but it doesn't have a built in support for paging,inserting ,deleting , updating the data. and if you looked at its laout , you will find that by default  the datalist renders as html table and you will have to set its flowLayout to "Flow" to stop that behaviour.
The Repeater control : you will find that it provides a flexible layout but it doesn't support data grouping ,inserting,deleting , updating  and paging through the data .