Advertisements

Archive

Posts Tagged ‘NET’

Set focus on textbox

November 16, 2016 Leave a comment

Using Jquery

$(function() {
  $("#Box1").focus();
});

Using Javascript
window.onload = function() {
  document.getElementById("Box1").focus();
};

HTML5 

http://www.codeproject.com/members/flair/8524963

Advertisements
Categories: ASP.NET, Code Project Tags: , , ,

How to create a Pie chart using ASP.Net and C#

December 23, 2013 Leave a comment

43

 

There are 4 things you need to do in order to get this configured and working on your machine, remember, however that you will need Visual Studio 2010 and .Net 4.
  • Create a Website project
  • Modify the Web.Config file
  • Modify the Default.aspx file
  • Modify the Default.aspx.cs file
I’ll assume you know how to create a Website project…File, New, Website, ASP.Net project…
The Web.Config file needs to be modified to contain the httpHandler and controls. These configurations enable the asp:Chart tag which is used in the Default.aspx file.

<httpHandlers>

  <add path="ChartImg.axd"
      verb="GET,HEAD,POST"
      type="System.Web.UI.DataVisualization.Charting.ChartHttpHandler,System.Web.DataVisualization,
      Version=4.0.0.0, Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"
      validate="false"/>
</httpHandlers>
<controls>
  <add tagPrefix="asp"
      namespace="System.Web.UI.DataVisualization.Charting"
      assembly="System.Web.DataVisualization,
      Version=4.0.0.0,
      Culture=neutral,
      PublicKeyToken=31bf3856ad364e35"/>
</controls>
In the Default.aspx file we will add the chart, titles, legend, series and chartareas.

<asp:chart id="Chart1" runat="server" Height="300px" Width="400px">

  <titles>
    <asp:Title ShadowOffset="3" Name="Title1" />
  </titles>
  <legends>
    <asp:Legend Alignment="Center" Docking="Bottom" IsTextAutoFit="False"
    Name="Default" LegendStyle="Row" />
  </legends>
  
  <series>
    <asp:Series Name="Default" />
  </series>
  <chartareas>
    <asp:ChartArea Name="ChartArea1" BorderWidth="0" />
  </chartareas>
</asp:chart> 
And lastly, we will add the code to the code-behind file to populate and configure the chart. First thing I do is to load the data values for the chart. If this was implemented in a program being used to represent real data, then the values would not be hardcoded. You would connect to a database, run a query and then have your business logic create the contents of the values. For simplicity, I hard coded the values. Then I simply went through and set the properties that created the above Pie Chart.

protected void Page_Load(object sender, EventArgs e)

{
  double[] yValues = { 71.15, 23.19, 5.66 };
  string[] xValues = { "AAA", "BBB", "CCC" };
  Chart1.Series["Default"].Points.DataBindXY(xValues, yValues);
  Chart1.Series["Default"].Points[0].Color = Color.MediumSeaGreen;
  Chart1.Series["Default"].Points[1].Color = Color.PaleGreen;
  Chart1.Series["Default"].Points[2].Color = Color.LawnGreen;
  Chart1.Series["Default"].ChartType = SeriesChartType.Pie;
  Chart1.Series["Default"]["PieLabelStyle"] = "Disabled";
  Chart1.ChartAreas["ChartArea1"].Area3DStyle.Enable3D = true;
  Chart1.Legends[0].Enabled = true;
}
Hope this help !

Comparing ListView with GridView,DataList and Repeater

April 13, 2012 Leave a comment

The ListView control is a new data presentation control that was added in ASP.Net 3.5.You may wonder why its added to the framework , and what it provide .

From what i have seen, ListView control was added to provide The following functionalities :

  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
Control Paging Data Grouping Provide Flexible Layout Update,Delete Insert Sorting
ListView supported supported supported supported supported supported
GridView supported Not supported Not Supported supported Not Supported supported
DataList Not supported supported supported Not supported Not supported Not supported
Repeater Not supported Not supported supported Not supported Not supported Not 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 .

Summary :

The ListView control was added to provide a rich data control that can support all the required functionalities at the same time , so now you can easily display a fully customizable layout that supports Grouping,paging , inserting , deleting , updating and sorting the data.