aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

{#advanced_dlg.about_title}
by Aamir Hasan   on Wednesday, November 17, 2010
Several times,this question has been asked that how to print a page in Silverlight, thanks to Microsoft who  have given this print support in Silverlight 4. Before going to start you must have installed Visual Studio 2010 and Silverlight 4.Let’s start. Open your Visual Studio 2010, from File -> New Project -> Select Silverlight template -> give a name and click OK button to continue. Following is the code of  Main.xaml file.<UserControl x:Class="Silverlight4_Printing.MainPage"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"    mc:Ignorable="d"    d:DesignHeight="400"  d:DesignWidth="560" xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">    <Grid x:Name="LayoutRoot" Background="White" HorizontalAlignment="Center">        <sdk:Label Height="28" HorizontalAlignment="Left" Margin="10,10,0,0" Name="label1" VerticalAlignment="Top" Width="297" />        <Button Content="Print" Height="23" HorizontalAlignment="Left" Margin="66,103,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />    </Grid></UserControl>Following is the code of  Main.xaml.cs file        public MainPage()        {            InitializeComponent();            label1.Content = "Welcome to aspxtutorial.com";        }        private void button1_Click(object sender, RoutedEventArgs e)        {            var document = new PrintDocument();            document.PrintPage += (s, args) =>            {                args.PageVisual = LayoutRoot; args.HasMorePages = false;                button1.Visibility = Visibility.Collapsed;            };            document.EndPrint += (s, args) =>            {                button1.Visibility = Visibility.Visible;            };            document.Print("Silverlight Print Page");        } Output Download Silverlight 4 - Printing page.zip (252.13 kb) See live demo
{#advanced_dlg.about_title}
by Aamir Hasan   on Sunday, August 29, 2010
Microsoft Silverlight 4 Tools for Visual Studio 2010 is available, Download Silverlight 4 Tool
{#advanced_dlg.about_title}
by Aamir Hasan   on Sunday, August 29, 2010
Visual Studio 2010 RC or Visual Web Developer Express 2010 RC or Visual Phone Developer Express 2010 that matches the language version of Silverlight Tools 4 must be installed before installation of Silverlight Tools can continue. Silverlight Tools is available in other languages at More
{#advanced_dlg.about_title}
by Aamir Hasan   on Friday, August 20, 2010
Microsoft recently introduce Silverlight 4, in Silverlight 4 Microsoft have remove old bugs and introduce some new features, in old version of Silverlight there is no support of print the application and double click event, now these all features are available in Silverlight 4 and more control and function are also given. New features and improvements contains the following sections Controls Out-of-Browser Media Networking Printing User Interface XAML Data Application Model Core Silverlight Designer Windows Phone Platform Support Related Topics   For more details and information click here MSDN What's New in Silverlight 4. Reference: Silverlight 4 : The Official Microsoft Silverlight Site
{#advanced_dlg.about_title}
by Aamir Hasan   on Friday, March 12, 2010
DropDown.zip (135.33 kb) LiveDemo   Introduction In this article i am  going to explore some of the features of the ComboBox.ComboBox makes the collection visible and allows users to pick an item from the collection.After its first initialization, no matter if you bind a new datasource with fewer or more elements, the dropdown persists its original height.One workaround is the following:1. store the Properties from the original ComboBox2. delete the ComboBox removing it from its container3. create a new ComboBox and place it in the container4. recover the stores Properties5. bind the new DataSource to the newly created combobox Creating Silverlight ProjectCreate a new Silverlight 3 Project in VS 2008. Name it as ComboBoxtSample. Simple Data BindingAdd System.Windows.Control.Data reference to the Silverlight project. Silverlight UserControl Add a new page to display Bus data using DataGrid. Following shows Bus column XAML snippet:The ComboBox element represents a ComboBox control in XAML.  <ComboBox></ComboBox>ComboBox XAML Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4 Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4         <StackPanel Orientation="Vertical">             <ComboBox Width="120" Height="30" x:Name="DaysDropDownList" DisplayMemberPath="Name">                 <!--<ComboBox.ItemTemplate>                     <DataTemplate>                         <StackPanel Orientation="Horizontal">                             <TextBlock Text="{Binding Path=Name}" FontWeight="Bold"></TextBlock>                             <TextBlock Text=", "></TextBlock>                             <TextBlock Text="{Binding Path=ID}"></TextBlock>                         </StackPanel>                     </DataTemplate>                 </ComboBox.ItemTemplate>-->             </ComboBox>         </StackPanel>     The following code below is an example implementation Combobox control support data binding     1 By setting the DisplayMemberPath property you can specify which data item in your data you want displayed in the ComboBox.    2 Setting the SelectedIndex allows you to specify which item in the ComboBox you want selected. Business Object Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4         public class Bus         {             public string Name { get; set; }             public float Price { get; set; }                   }   Data Binding Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4         private List<Bus> populatedlistBus()         {             listBus = new List<Bus>();             listBus.Add(new Bus() {Name = "Bus 1", Price = 55f });             listBus.Add(new Bus() { Name = "Bus 2", Price = 55.7f });             listBus.Add(new Bus() { Name = "Bus 3", Price = 2f });             listBus.Add(new Bus() { Name = "Bus 4", Price = 6f });             listBus.Add(new Bus() { Name = "Bus 5", Price = 9F });             listBus.Add(new Bus() { Name = "Bus 6", Price = 10.1f });               return listBus;         }   The following line of code sets the ItemsSource property of a ComboBox. Normal 0 false false false EN-US X-NONE X-NONE MicrosoftInternetExplorer4         List<Bus> listBus;         public MainPage()         {             InitializeComponent();             DaysDropDownList.ItemsSource = populatedlistBus();         }   Output I hope you enjoyed this simple Silverlight example Conclusion In this article, we saw how data binding works in ComboBox.You learnt how to work with the ComboBox control in Silverlight. DropDown.zip (135.33 kb) LiveDemo  
{#advanced_dlg.about_title}
by Aamir Hasan   on Wednesday, March 10, 2010
  DataGridSilverlightApplication.zip (1.87 mb) Live Demo Introduction In this article I will show you the basics of the DataForm control. what you can do with it and why you should use it. I will show you how you can bind an item or a collection of items to a data form.The DataForm control is like the DataGrid control in Silverlight 2. But while the DataGrid control is used to manipulate a list of items, the DataForm control focuses on the item itself. DataGridDataGrids are fundamental UI controls for almost all line of business applications.Simplify the task of displaying structured data to users by automatically handling the rendering of rows, columns, headers, and data navigation. Silverlight's data grid is no exception. The Width and Height attributes represent the width and the height of a DataGrid.  The x:Name  attribute represents the name of the control, which is a unique identifier of a control.  The Margin attribute sets the margin of the DataGrid being displayed from the top left corner. The following code sets column width and row height to 680 and 270 respectively.  <data:DataGrid x:Name="McDataGrid" Width="680" Height="270"       Margin="10,10,0,0" Background="Gray”></data:DataGrid>Setting Column Width and Row HeightThe ColumnWidth and RowHeight properties of DataGrid are used to set the default column width and row height of DataGrid columns and rows.  ColumnWidth="100" RowHeight="40"<data:DataGrid x:Name="McDataGrid" Width="680" Height="270"  Margin="10,10,0,0" Background="Gray"  ColumnWidth="100" RowHeight="40"></data:DataGrid>SortingBy default, column sorting is enabled on a DataGrid. You can sort a column by simply clicking on the column header.  You may disable this feature by setting CanUserSortColumns property to false. The following code snippet sets CanUserSortColumns properties to false.CanUserSortColumns = "False"ScrollingThe HorizontalScrollBarVisibility and VerticalScrollBarVisibility properties of type ScrollBarVisibility enumeration control the horizontal and vertical scrollbars of the DataGrid. It has four values - Auto, Disabled, Hidden, and Visible. The default value of these properties is Auto, that means, when scrolling is needed, you will see it, otherwise it will be hidden.The following code enables the horizontal and vertical scrollbars. HorizontalScrollBarVisibility="Visible"VerticalScrollBarVisibility="Visible"Properties 1.    AutoCommit – indicates whether to save the changes if the user presses the next (or the previous) button without pressing the Save button2.    AutoEdit – indicates whether to go into Edit mode automatically when you select a record3.     CancelButtonContent – lets the user set a content for the Cancel button4.     CommitButtonContent – lets the user set the content for the Commit button5.    CanUserAddItems – determines whether the user can add new items or not6.    CanUserDeleteItems – determines whether the user can delete an existing item or not7.     DescriptionViewerPosition – sets the position of description (each field may have a description8.    Header – sets the header of the form9.    AutoGenerateFields – indicates whether fields should be automatically generated or not. Adding the Assembly to Use a DataGrid Control We will display our data using the DataGrid control, but Silverlight does not include a reference to the DataGrid control by default, so we need to add one. This process is very similar to using a custom control in ASP.NET. Recall that we add a reference to the appropriate DLL in the project and then add a register tag in the aspx page. To achieve this in Silverlight, add a new reference (right click on References and select New Reference) and locate System.Windows.Controls.Data in the list (this is the assembly that contains the DataGrid).Referencing assembly for DataGrid controlAfter this reference is added, we need to assign a namespace to this assembly in our XAML markup. To do this, add the following to the namespace declaration of the file Page.Xaml.The DataGrid is contained in the System.Windows.Controls  namespace. It can be dragged from the tool box to a XAML page. To use the DataGrid, we need to add the following namespace to our page:xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" Adding the DataNow that we have a Data Grid to use called dataGrid1,  we can prepare some data to display in the grid.  In this example, we'd like to display customer information.  Each row of the DataGrid will represent one customer.  First we'll need a customer entity to work with, so we'll create a Customer class.  We'll use automatic properties for each property used to describe customer information such as name or email.   public class Employee { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string City { get; set; } public string FatherName { get; set; } public string PhoneNo { get; set; } public bool Status { get; set; } }   we have our Employee, we are ready to create a datasource to attach  to our DataGrid.  You can use any collection in .NET that supports IEnumerable to be the datasource for our DataGrid,  but you'll want to use an ObservableCollection if you want to have the ability to add and remove Employees from the collection and have them be reflected in the Grid   private List populatedlistEmployee() { listEmployee = new List(); listEmployee.Add( new Employee() { ID = 1, FirstName = "Aamir", LastName = "Hasan", City = "ISB",FatherName="Zahoor ahmed",PhoneNo="092-333-5494532",Status=true }); listEmployee.Add( new Employee() { ID = 2, FirstName = "Awais", LastName = "Ahmed", City = "isb", FatherName = " ahmed", PhoneNo = "--", Status = false }); listEmployee.Add( new Employee() { ID = 3, FirstName = "Ali", LastName = "hasan", City = "Rwp", FatherName = "hasan ahmed", PhoneNo = "--", Status = false }); listEmployee.Add( new Employee() { ID = 4, FirstName = "Hasan", LastName = "khan", City = "Lha", FatherName = "ali ahmed", PhoneNo = "--", Status = false }); listEmployee.Add( new Employee() { ID = 5, FirstName = "Ahmed", LastName = "ali", City = "Pwe", FatherName = "hasan khan", PhoneNo = "--", Status = false }); listEmployee.Add( new Employee() { ID = 6, FirstName = "Bill", LastName = "gate", City = "new jersey", FatherName = "--", PhoneNo = "--", Status = true }); return listEmployee; }  Assigning the data to the DataGrid's ItemSource   public Page() { InitializeComponent(); McDataGrid.ItemsSource = populatedlistEmployee(); } Output Below is the output screen shot. Now we have all the pieces in place to display the DataGrid on our Silverlight Web Page.  Let's look at the results shown in figure 3.  All the Employees in the Employees collection are displayed initially in our application.  To edit a cell, we simply click in the cell we want to edit and type our changes.  These changes will then be reflected in our Employees collection.  Conclusion The future of solid and rich web development is not ever going to be found in the raw browser.  It will be much more readily found in applications that can be embedded in the browser.  I'm looking forward to leveraging the power of Silverlight in the months to come. In this article, we learnt how to use a DataGrid control in Silverlight. I will add more DataGrid functionality to this article in my next update. If you developed any cool code and want to share here, feel free to post at the bottom. The entire source code of this article can be downloaded over Here DataGridSilverlightApplication.zip (1.87 mb) Live Demo
Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5