Pages

Friday, July 9, 2010

SCROLLVIEWER control in Silver light

Hi all,

This time I am simply showing that how easily can we use a Scroll bar effect in our silver light page.. Scroll bar important in the page when there is an item which is not fully displayed inside the control, and we need to either Scroll UP or Scroll side to view the content completely. This Scroll bar can be taken either Horizontally or vertically and can be used either in a page panel or inside a text box to provide the scrolling functionality for its containing control..

This is a Inbuilt control for the Silver light, I am using the VS2010 and Silver Light 4 to create this sample applciation..Please look at the code for the page..

x:Class="ScrollViewerSample.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="300" d:DesignWidth="400">

x:Name="LayoutRoot" Background="White">
VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" Margin="10,20,120,15">
Image Source="Bhokal.jpg" Stretch="Fill" Width="400" Height="400" >
>
>
>
>


(Due to browser problem the "<" and ">" tag are disables please include them.)


Here as you can see , simply I have taken the SCROLLVIEWER control and sets its "VerticalScrollBarVisibility" and "HorizontalScrollBarVisibility" property to true. We can set the Source of a Image(Eg. I am taking an IMAGE here), or we can also take the control like TEXTBOX.


While the Design time the page is like this...



and You can see How our SCROLLVIEWER control is working while running the application...
here is the Output screen for the application.




Hope You have like this sample, Please feel free to post your comment..



Thanks
Anil Kumar Pandey
Micorsoft MVP (C#)
Navi Mumbai,
Maharashtra

Thursday, July 1, 2010

New MVP Announce..

Microsoft MVPs are awarded every quarter and recognize the contributions of an individual to technical communities over the past year.

We are extremely happy to welcome the following new MVPs amongst our midst for this quarter:

Vinoth Rajagopalan

Windows Embedded

Jalpesh vadgama

Visual C#

Shiju Varghese

ASP/ASP.NET

Amol Ghuge

SharePoint Server

Rajesh Sitaraman

SharePoint Server

Malleswara Reddy

Device Application Development

Manu Philip

Exchange Server

Krishna R

PowerShell

Binu Bhasuran

Visual C#

Ramesh Swaminathan

ASP/ASP.NET

Pradeep Kumar

Visual Basic

Dhan Bansal

Dynamics NAV

Asheej TK

ASP/ASP.NET

Arun Kumar

Internet Explorer


Congratulations to all the MVP awardees, and the renewed MVPs, for this prestigious award! We are glad to have a Powershell and Internet Explorer MVP amongst us now.

To know more about the MVP Program, please visit: http://www.microsoft.com/india/mvp

Wednesday, June 2, 2010

Most Valuable Member (DotNetSpider)

Hi all,
I am very happy to inform you all that i have received the Most Valuable Member of the prestigious dot net community site www.dotnetspider.com. here is the certificate from them.

Thank you all for your support.



Thanks
Anil Kumar Pandey
Micorsoft MVP (C#)
Navi Mumbai,
Maharashtra

Monday, May 24, 2010

Windows Communication Foundation (WCF) - A sample application

Hello all,
We all know that the Windows Communication Foundation (WCF) is the latest technology for communication between application, just like the web service but there are some more powerful features also in the WCF. We all know that WCF is very common now a days so for here i am going discuss that how can we create a sample web service in which we can interact with the data base also.
In this WCF sample i am going to check that weather a given user name is invalid or not.We can furture implement the service for some more use..

1. So for the first step start the Visual Studio Select New Website and choose a WCF service like



Give the Site name as "CheckUser_WCF".

2. In the Next Step you will be directed to the Following page "APP_CODE/Service.cs". In that page create a function which will read the table from data base for that create a simple data base with a name "UserData" and in that create a table as "UserInfo". Insert some sample records also the table will be like..


3. In the Next Step add a function decalrtion in the service interface name "IService.cs" which you can find inside the "App_Code" folder. Simply add the following lines there.

[OperationContract]
Int32 GetUserId(string strUserName);

here [OperationContract] denotes that this function is going to perform action in the service which will intact with the user. We must declare a function as "[OperationContract]" if we are assigning it some functionality..

Now the page will be like this.


4. Now in the next step create the "GetUserId" function in the service code file which will accept the user name as input. The User name will be entered by the user in our testUser.aspx page

public Int32 GetUserId(string strUserName)
{
SqlConnection con
= new SqlConnection("Data Source = GP-000\\SQLEXPRESS; Initial Catalog = UserData; User ID = sa; Password = test;");
string cmd = "select UserID from UserInfo where UserName = '" + strUserName + "' ";
SqlDataAdapter da
= new SqlDataAdapter(cmd, con);
con
.Open();
DataSet ds
= new DataSet();
da
.Fill(ds);
con
.Close();

if(( ds.Tables[0].Rows.Count>0) && Convert.ToString(ds.Tables[0].Rows[0][0].ToString()) != "")
{
return Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
}
else
{
return 0;
}}

now the page will look like this..



Now your Service is ready you can build the application and can run it. After running it you will get the following output.


5. In the next step you use the URL for the service which is appearing in the Browser as "http://localhost:4771/CheckUser_WCF/Service.svc" for any other application where you want to use that or else you can also use it in the same application. For that simply Right click on the solution and Select the "Add Service Reference" option, a new window will be opened and there you can pass the URL of the service "http://localhost:4771/CheckUser_WCF/Service.svc" in the place of address and simply click go the window will discover you service assign it a name as "UserService" The dialog box will be like this


Click on ok and the reference will be added in the application which you can see in the Solution explorer.. In this sample I am going to use it in same application only for that i am going to create a sample test page.

* Add a new ASPX page in the application give it the name as "testUser.aspx" It will look like this..


6. In the Code behind page simply create the button click functionality as

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class testUser : System.Web.UI.Page
{
UserService
.ServiceClient wcfService = new UserService.ServiceClient();

protected void Page_Load(object sender, EventArgs e)
{
lblMsg
.Text = "";
}


protected void CheckUser_Click(object sender, EventArgs e)
{
string strName = "";
int intResult = 0;
strName
= textUsername.Text.Trim();

if (strName != "")
{

intResult
= wcfService.GetUserId(strName);
}

if (intResult > 0)
{
lblMsg
.Text = "User is valid";
lblMsg
.ForeColor = System.Drawing.Color.Green;
}
else
{
lblMsg
.Text = "User is invalid";
lblMsg
.ForeColor = System.Drawing.Color.Red;

}
}
}

For creation the object of the service simply use the service name and create like this..

UserService.ServiceClient wcfService = new UserService.ServiceClient();

with the help of this object we can call all the function inside the service which are available for us..

Here now application is ready which will check that weather the specified user name is present in the data base or not.. Run the application and you will get the out put will be like this if a user is INVALID


and this if the user is a valid user




This is piety simple i hope you have like this article.. Please feel free to put your comment..

Thanks
Anil Kumar Pandey
Micorsoft MVP (C#)
Navi Mumbai,
Maharashtra


Thursday, April 29, 2010

Working with the Data Grid in Silver Light..

Hello all,

We have all worked in ASP.NET data grid and that is simple. The same data grid is also there is Silver Light but a slightly different. While searching for some stuffs i came across several articles on the same topic so i thought to share the same with you all peoples hope you like this small article.
Here simply i am taking a data grid inside the silver light page and i will show that how can be bind the grid easily. A Data grid control sets its height and width according to the page. set the auto generate column property as false, set the name as "dgPersonal" Taking some columns like ID, First Name, Last Name and Email. Using the BINDING property of the grid to bind them. Please check the following XAML code


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" xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data" x:Class="Silverlight_Data_Grid.MainPage"
d:DesignWidth="640" d:DesignHeight="480">
x:Name="LayoutRoot">

Margin="5" x:Name="dgPersonal" Height="400" VerticalAlignment="Top" HorizontalAlignment="Center" GridLinesVisibility="All" AutoGenerateColumns="False">
>
Header="User ID" Width="70" Binding="{Binding UserID}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False">>
Header="First Name" Width="150" MinWidth="150" CanUserReorder="False" SortMemberPath="FirstName">
>
>
Text="{Binding FirstName}" ToolTipService.ToolTip="{Binding FirstName}" FontFamily="Arial" FontSize="11" VerticalAlignment="Center" Margin="5,0,0,0" />
>
>
>
Header="Last Name" Width="150" MinWidth="150" Binding="{Binding LastName}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False"/>
Header="Email Address" Width="150" MinWidth="150" Binding="{Binding EmailID}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False"/>
Header="Contact" Width="100" MinWidth="100" Binding="{Binding ContactNumber}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False"/>
Header="Date Of Birth" Width="160" MinWidth="160" Binding="{Binding DateOfBirth}" CanUserSort="True" IsReadOnly="True" CanUserReorder="False"/>
>
>

>
>



The GRID will look like this, please take a look..


On the other hand in the code behind file will be like this.


using System;
using System.Collections.Generic;
using System.Windows.Controls;

namespace Silverlight_Data_Grid
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent
();
dgPersonal
.ItemsSource = Persons.GetDataItems();
}

}



here inside the main page we are simply binding the grid from the list. I have made a class for that named as PERSON.This class is creates in another class file which is named as MyData, the Person class consist of the different member variables like the UserID, Firstname, Lastname & email etc.
for creating a data source the Generic list is used inside that we are binding the records. Please take a look towards the code behind file.


using System;
using System.Collections.Generic;

namespace Silverlight_Data_Grid
{
public class Persons
{

public string UserID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string EmailID { get; set; }
public string ContactNumber { get; set; }
public DateTime DateOfBirth { get; set; }

public static List<Persons> GetDataItems()
{
List
<Persons> myPersonList = new List<Persons>
{
new Persons{ UserID="Anil", FirstName="Anil", LastName="Kumar", EmailID="anilk@pandey.com", ContactNumber="123456789", DateOfBirth=DateTime.Now.AddYears(-28)},
new Persons{ UserID="Abdul", FirstName="Abdul", LastName="javed", EmailID="abdul.javed@pandey.com", ContactNumber="123456789",DateOfBirth=DateTime.Now.AddYears(-27)},
new Persons{ UserID="chetanD", FirstName="Chetan", LastName="Desai", EmailID="chetan.desai@pandey.com", ContactNumber="123456789",DateOfBirth=DateTime.Now.AddYears(-32)},
new Persons{ UserID="manoj", FirstName="Manoj", LastName="Verma", EmailID="manojv@pandey.com", ContactNumber="123456789",DateOfBirth=DateTime.Now.AddYears(-30)},
new Persons{ UserID="vinod", FirstName="Vinod", LastName="Yadav", EmailID="vinod@pandey.com", ContactNumber="123456789",DateOfBirth=DateTime.Now.AddYears(-29)},
new Persons{ UserID="swati", FirstName="Swathi", LastName="s", EmailID="swati@pandey.com", ContactNumber="123456789",DateOfBirth=DateTime.Now.AddYears(-22)}
};
return myPersonList;

}
}
}


That's it from the coding side now we are ready to run the application.. Because the sort property is set so we can also sort the data grid records based on the column.After running the application the output will be like this.



Isn't it so simple. I too was very comfortable dealing with this grid in the silver light. We can explore more things inside the grid by our own. The main concept of this article was taken from one of the community sites of the official Microsoft Silver Light site that is http://www.silverlight.net Please feel free to comment on the article waiting for your comments....



Thanks
Anil Kumar Pandey
Micorsoft MVP (C#)
Navi Mumbai,
Maharashtra



Kontera