-->

Monday, July 27, 2015

How to bind ListBox in wpf

Today i am taking about listBox in WPF. In previous articles of windows form and web form i already discussed about  ListBox. In this article i will use same control in different technology(WPF). We know that ListBox is a container of Objects. Listbox contain ItemsSource property of it which is used to bind it with the database table. You can manually define the listbox items using ListBox itemTemplate. Look at this example :


<Grid>
        <ListBox ItemsSource="{Binding Path=emp}" x:Name="listBox" HorizontalAlignment="Left" Height="225" Margin="58,48,0,0" VerticalAlignment="Top" Width="218">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Path=Emp_Id}"/>
                        <TextBlock Text="{Binding Path=Emp_Name}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>

        </ListBox>


    </Grid>

Code behind code

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace SplashSCreen
{
    /// <summary>
    /// Interaction logic for bindlist.xaml
    /// </summary>
    public partial class bindlist : Window
    {
        public bindlist()
        {
            InitializeComponent();
            loadlist();
        }

        private void loadlist()
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = ConfigurationManager.ConnectionStrings["connsetting"].ToString();
            con.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "select * from [emp]";
            cmd.Connection = con;
            DataSet ds = new DataSet();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds, "emp");
            listBox.DataContext = ds;

        }
    }
}

Binding process in the code behind model are same in windows form as well as web forms. Only one difference that is DataSource, here we use DataContaxt.

Code generate the following output:

How to bind ListBox in wpf

Saturday, July 18, 2015

Internet explorer input box show password eye button

Internet explorer's input box show the password when we click on eye button. When we press the button then show the password but when we release it then input character automatically convert into password format. Today, in this article we will design the input box whose will show the password just like eye button. This article designed in html and functionality of the article will handle by JQuery.

The complete code available in the video, so see this and learn more things about JQuery:



In this video, i have two text box, first is used for hide the password and second is used for show the password. When first time load the browser then hide second text box. When user click on show password  button then second textbox take the value of first text box also hide first text box and show second. 

How to Bind Adrotator control in asp.net

Introduction
The Adrotator control displays a sequence of images, known as advertisements, on a Web page. The sequence in which the images appear can be predefined or random in nature. These advertisements, which all Internet users are familiar with, are image files in GIF, JPEG, or other format that the user can click to navigate to the advertiser's website.

Public Properties of the Adrotator Class
 AdvertisementFile : Obtains or sets the path to an XML document that contain advertisement information.



Design a xml file for advertisements name as "advertisements.xml" 
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
  <Ad>
    <ImageUrl>security.JPG</ImageUrl>

    <Width>
    200px
  </Width>
    <Height>
      200px
    </Height>
  </Ad>
<Ad>
    <ImageUrl>images.JPG</ImageUrl>
<Width>
    100px
  </Width>
<Height>
      200px
    </Height>
  </Ad>
</Advertisements>
Drag and drop adrotator control onto the design window from toolbox


<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>  
        <asp:AdRotator ID="AdRotator1" runat="server" AdvertisementFile="~/advertisements.xml" />
        </div>
    </form>
</body>
</html>
Output
How to bind adrotator control in asp.net

How to bind Adrotator control in asp.net

How to bind label control in asp.net

Step-1: Open Visual Studio IDE
Step-2 : Create New Web Project

ASP.NET empty website


Step-3: In Solution Explorer Add new item 
Solution Explorer Add new item


Step-4: Select web form in middle pane also select c# in left pane

Step-5: Change name of the webform as "labelbind.aspx" also select place code in separate file check box
Step-6:   Right click on  Project name and add new item  again.
Step-7: Open a new dialog window Select SQL SERVER database  name as a "database.mdf"
Step-8: After click ok Button . a new dialog appear on the screen 
Do you want to place the file in App_data folder
Step-9: Click Ok Button in dialog window
Step-10: Open Server Explorer
Step-11 Make a new table inside Database

Step-12:
make a new table


Step-13: fill This Table with Some value
Step-14: Open  " labelbind.aspx " page
Step-15: Drag and Drop label control onto the labelbind.aspx page from toolbox

Step-16: Add this code in Design page



<%@ Page Language="C#" AutoEventWireup="true" CodeFile="labelbind.aspx.cs" Inherits="labelbind" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="">
            UserId:<%# myname %>


        </asp:Label>
    </div>
    </form>
</body>
</html>

Step-17 Add this code in .cs file


using System;
using System.Data.SqlClient;

public partial class labelbind : System.Web.UI.Page
{
    public string myname;
    SqlConnection con = new SqlConnection();
    SqlCommand cmd = new SqlCommand();


    protected void Page_Load(object sender, EventArgs e)
    {
        con.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
        con.Open();
        cmd.CommandText = "select * from [Employee]";
        cmd.Connection = con;
        SqlDataReader rd = cmd.ExecuteReader();
        while (rd.Read())
        {
            myname = rd["Emp_Name"].ToString ();

        }
        this.DataBind();

     

    }
}


OutPut 


bind label output

Friday, July 17, 2015

Student and fees management project in c#

Introduction 
This project is related to school management system. In this project we have a Sql Database to store student information also store their fees details. The main motive behind the project is to persist the student information in single place. So,we can retrieve that information easily and quickly.

Front-end and Back-end:
Front-end : Windows form with c# as business logic
Back-end :  SQL Server 2014

How to run this:


How to design the system

  1. First to add new windows form in the solution.
  2. Add some control in the form.
  3. Now, add business logic in the code file.
Module in the project
  1. Add new Student: Through this module we can add student details like : Student name, Student father name , Student mother name, Student address etc.
  2. Edit Details :  You can edit details of student by their enrollment id.
  3. Search Student details : You can search stored student details by student name. In this project we can add auto complete type functionality.
  4. Delete Student Details
How to Download :  Mail me : narenkumar851@gmail.com

Monday, July 13, 2015

Use of ProgressBar in WPF also add it in Status bar with animation effect

In this article i will show you, how to use progress bar in wpf (Window Presentation Foundation) and how to add it in status bar dynamically. Actually i explained it with basic information, today i will explain more about it. In this article, first to add a status bar in the page after that add a TextBlock control in it. Now the code look like :


<Grid>

        <StatusBar Name="sbar1" Background="BlueViolet" VerticalAlignment="Bottom">
            <StatusBarItem>
                <TextBlock>Status:</TextBlock>
            </StatusBarItem>
        </StatusBar>
    </Grid>

Now, create a new function just after the InitializeComponent() method, it means you can view your progress bar on window load.  

Code behind code

using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Animation;

namespace WpfApplication2
{
    /// <summary>
    /// Interaction logic for progressbar.xaml
    /// </summary>
    public partial class progressbar : Window
    {
        public progressbar()
        {
            InitializeComponent();
            
            createprogressbar();
        }

        private void createprogressbar()
        {
            ProgressBar pb2 = new ProgressBar();
            pb2.IsIndeterminate = false;
            pb2.Orientation = Orientation.Horizontal;
            pb2.Width = 100;
            pb2.Height = 25;
           
            Duration dur = new Duration(TimeSpan.FromSeconds(30));
            DoubleAnimation dblani = new DoubleAnimation(200.0, dur);
            pb2.BeginAnimation(ProgressBar.ValueProperty, dblani);
            sbar1.Items.Add(pb2);

        }

  
    }
}

Now, code generate the following output:

Use of ProgressBar in WPF also add it in Status bar with animation effect


Here,
  1. Create a ProgressBar class object also set some data members like width, height etc.
  2. Set the animation by BeginAnimation method( )

Sunday, July 12, 2015

Accept only number by TextBox using Jquery

You can say, how to apply restriction on input using Jquery. Here, meaning of restriction is, TextBox accept only numbers. Everyone know that TextBox control take character,string, numeric and special character as a input. But in some application we need only single feature like, it accept only number. So, the first question raise in my mind, how to do this, what is the logic behind this.
Logic behind this:
  1. First to get the key code like number 8 == backspace, some following keycode available here 
  2.  Now, match the keycode with the input character, if match then input character are not allowed.
Here are simple example of it:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Accept only numbers</title>
<script src="scripts/jquery-1.10.2.js"></script>
<script>
$(function () {
$('#Text1').keydown(function (er) {

if (er.altKey || er.ctrlKey || er.shiftKey) {
er.preventDefault();
}
else {

var key = er.keyCode;
if (!((key == 8) || (key == 46) || (key >= 35 && key <= 40) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {

er.preventDefault();
}

}


});

});

</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
<input id="Text1" type="text" />
    </div>
    </form>
</body>
</html>
Now code generate the following output:

Accept only number by TextBox using Jquery
Here are some related article:
© Copyright 2013 Computer Programming | All Right Reserved