-->

Friday, July 12, 2013

How to use BulletedList Control in ASP.NET

Introduction
The BulletedList control is a standard web server control used to display items in the form of a bulleted list on a web page.
This control has no non-inherited methods. The BulletedList inherits the ListControl class.
Public Properties of the BulletedList class
AutoPostBack : Obtains or sets the value of the AutoPostBack property of the control for the base class
BulletImageUrl : Obtains or sets the path to an image to display each bullet in a control.
BulletStyle : Obtains or sets the style of the bullets for the BulletedList control.
Controls : Obtains a ControlCollection collection for the control.
DisplayMode : Obtains or sets the display mode of the list items appearing in a BulletedList control.
FirstBulletNumber : Obtains or sets the value that starts the numbering of list items in an ordered BulletedList control
SelectedIndex: Obtains or sets the zero based index of the currently selected item in a bulletedList control.
SelectedItem : Obtains the currently selected item in a BulletedList control.
SelectedValue : Obtains or sets the value property of the selected ListItem object in the BulletedList control.
Target : Obtains or sets the target window to display the data of the Web page that is linked to when a hyperlink in a bulletedList control is clicked.
Text : Obtains or sets the text for the BulletedList control.
Public event of the BulletedList class
Click : Occurs when a link button in a BulletedList control is clicked.

To specify the bullet type to display the list item in a bulleted list control. you can set the BulletStyle property to one of the bullet types that are defined by the BulletStyle enumeration.

Bullet style of the BulletedList Control
NotSet : Represents an unspecified bulleted list style the browser automatically sets the style of the bulleted list.
Numbered : Represents the bullets in the form of numbers.
LowerAlpha : Represents the bullets in the form of lowercase letters.
UpperAlpha : Represents the bullets in the form of uppercase letters.
LowerRoman : Represents the bullets in the form of lowercase Roman numerals.
UpperRoman : Represents the bullets in the form of uppercase Roman numerals.
Disc : Represents the bullets in the form of a filled circle.
Circle : Represents the bullets in the form of a empty circle.
Square : Represents the bullets in the form of a filled square.
CustomImage : Represents the bullets in the form of a custom image.

Example of BulletedList Control

Database table
bulletdatabase

Code
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void BulletedList1_Click(object sender, BulletedListEventArgs e)
    {
        if (e.Index ==0)
        {
            Image1.ImageUrl = "~/images/heroAccent.png";           
           
        }
        if (e.Index ==1)
        {
            Image1.ImageUrl = "~/images/orderedList0.png"; 
        }
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>   
        <br />
        Click the name to see the user&#39;s photo<asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="SqlDataSource1" DataTextField="username" DataValueField="Id" DisplayMode="LinkButton" OnClick="BulletedList1_Click">
        </asp:BulletedList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [usertable]"></asp:SqlDataSource>   
    </div>
        <asp:Image ID="Image1" runat="server" Height="110px" Width="110px" />
        <br />
    </form>
</body>
</html>
Output

bulleted list
Related article



Wednesday, July 10, 2013

Address Book Project in c#

Introduction:
Address book stores information of your family member or other person. This project contain some forms such as login form .
login form


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AddressBook
{
    public partial class LoginForm : Form
    {
        Thread appThread;
        public LoginForm()
        {
            InitializeComponent();
        }
        private void loginButton_Click(object sender, EventArgs e)
        {
            if (unameTextBox.Text == "admin" && passwordTextBox.Text == "password")
            {
                this.Close();
                appThread = new Thread(LaunchAdminApplication);
                appThread.SetApartmentState(ApartmentState.STA);
                appThread.Start();
            }
            else
                MessageBox.Show("Invalid Credentials", "Login Error!");
        }
        private void LaunchAdminApplication()
        {
            Application.Run(new MainForm());
        }
    }
}
Here  "unameTextBox" is the name property of the username textbox and "passwordTextBox" is the property of Password text box . if username and password are right then you can enter into new thread. A message box generated if your  username and password are wrong .

manage form


If you want to purchase this please contact me on :  narenkumar851@gmail.com

Monday, July 8, 2013

Crime File management System Project in ASP.NET

Aim of the project
The basic aim of this project is store criminal record ,  search criminal record and find current location of the criminal.

Security of the project :

Project contain username and password field for security with proper validation (client side and server side validation) . Project security screen shot is

crimefile



  <p>
        <h2>Login for security</h2></p>
    <asp:ValidationSummary ID="ValidationSummary1" runat="server" BackColor="#CCCC00" BorderColor="Black" BorderStyle="Solid" BorderWidth="4px" />
        <p>
        Enter member username :&nbsp;
        <asp:TextBox ID="usrtxt" runat="server" Width="182px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="usrtxt" ErrorMessage="Enter Username" ForeColor="Maroon">*</asp:RequiredFieldValidator>
    </p>
    <p>
        Enter&nbsp; member password : <asp:TextBox ID="pwd" runat="server" TextMode="Password" Width="182px"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="usrtxt" ErrorMessage="Enter password" ForeColor="Maroon">*</asp:RequiredFieldValidator>
    </p>
    <p>
        <asp:Button ID="Button1" runat="server" Text="Member Login" OnClick="Button1_Click" />
    </p>
    <p>
        <asp:Label ID="Label1" runat="server"></asp:Label>


Code behind code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class welcome : System.Web.UI.Page
{
 SqlDataReader rd;
protected void Page_Load(object sender, EventArgs e)
{
}
 protected void Button1_Click(object sender, EventArgs e)
{
 bool flag=true ;
using (SqlConnection con = new SqlConnection())
{
 con.ConnectionString =ConfigurationManager .ConnectionStrings ["ConnectionString"].ToString ();
con.Open ();
using (SqlCommand cmd=new SqlCommand ())
{
 cmd.CommandText ="select * from [Table]";
cmd.Connection =con;
rd=cmd.ExecuteReader (CommandBehavior .CloseConnection);
while (rd.Read ())
{
 if (rd["username"].ToString ().Equals(usrtxt .Text) && rd["password"].ToString ().Equals (pwd .Text))
{
 flag =false ;
 Session ["username"]=rd["username"].ToString ();
break ;
}
}
 if (flag ==true)
 Label1 .Text ="No record found";
else
 Response .Redirect ("~/admin/securepage.aspx");
}
}
}
}
Software requirements of the project are:
  • Visual studio 2013
How to run this project:
  • Open website in  visual studio 2013
  • Run your project
  • ByDefault your username and password are : admin and admin



Your project will submit after 5 hour 


Sunday, July 7, 2013

Round off value in DataGridView Cell

In most of the situations programmer want to save value in decimal data type, but try to show that value in approximate format. For example we have a variable "income" that have some different value as below
income = 3.57 (stored in database exactly)
income = 3.6 (programmer want to show the user)

The decimal data type can store maximum of 38 digits. It stores exact representation of the number, there is no approximation of the stored value. Decimal data type can be used to store numbers with decimals when the values must store exactly as specified. We can read more about decimal values from http://msdn.microsoft.com/en-us/library/ms187912(v=sql.105).aspx

In above case programmer want to round off that value at run time binding. As we know about datagridview binding in which data will be shown as same as they are stored in our database. When we bind our list to datagridview it means we are binding each cell one by one. If we want to check which cell is binding to what value then we can do this in Cell Formatting event of datagridview.

Datagridview cell formatting event occurs when the contents of a cell need to be formatted for display. If the standard formatting is insufficient, we can customize the formatting by handling this event. This event occurs every time each cell is painted. Go through datagridview cell formatting event if you want to know more about cell formatting event.

Your cell formatting event should look like the below code if you want to round off all the decimal values bind to this datagridview.

private void dataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
double decValue;
if (e.Value == null)
return;
if (double.TryParse(e.Value.ToString(), out decValue) == false)
return;
e.Value = Math.Round(decValue);
}

This code will work only with decimal values. It will do nothing if either “value is null” or “value is not type of decimal”. If the value is of type decimal it will round off that value using Math.Round() method. This method rounds a value to its nearest integral value.

Saturday, July 6, 2013

How to check minimum or maximum value of integer data type

According to msdn ,  minimum and maximum value of Integer datatype are : -2,147,483,648 to 2,147,483,647.

Let's have an example :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace tutorial
{
   class Program
 {
   static void Main(string[] args)
 {
   int a = 0;
Console.WriteLine("minimum value of" + int.MinValue);
Console.WriteLine("maximum value of" + int.MaxValue);
Console.ReadKey();
 }
 }
}

Output
output
Here:
 MinValue field Represents the smallest possible value of System.Int32. This field is constant.
MaxValue field Represents the largest possible value of System.Int32. This field is constant

 

Wednesday, July 3, 2013

Use XML file as database

Sometimes, when we are creating small application, we have to use SQL Server database if we don’t know about any alternative solution. SQL Server databases are very familiar with programmers, but if our application is small then we don’t let the user install and maintain any database engine.



We have an alternative solution i.e. XML (Extensible Markup Language) files that is a textual data format. It is widely used for the representation of arbitrary data structures, for example in web services. We can read more about Xml files through http://en.wikipedia.org/wiki/XML.



To work with XML files we use XmlSerializer class that serializes and deserializes objects into and from XML documents. It is in System.Xml.Serialization namespace and enables us to control how objects are encoded into XML. The most important methods in this class are Serialize and Deserialize.



In this article we will serialize a class Person consists of public properties, as shown below:

public class Person
{
     public string Name { get; set; }
     public string FName { get; set; }
     public int Age { get; set; }

}

Write data to XML file:

To write data in XML file we use Serialize method that serializes the specified object and writes the XML document to a file using the specified stream. It takes two parameters.

First parameter will be used to write the data to file, it may be either a FileStream or an XmlWriter. Second parameter is the data that is to be written.



List<Person> personList = new List<Person>();
XmlSerializer serializer = new XmlSerializer(typeof(List<Person>));
using (FileStream stream = new FileStream(Environment.CurrentDirectory + "\\file.xml", FileMode.Create, FileAccess.Write))
{
    serializer.Serialize(stream, personList);
}



In above code


  • Add some data to personList that are to be written to file.
    personList.Add(new Person() { Name = "Student1", FName = "Father1", Age = 25 });
    personList.Add(new Person() { Name = "Student2", FName = "Father2", Age = 24 });
    personList.Add(new Person() { Name = "Student3", FName = "Father3", Age = 26 });
    personList.Add(new Person() { Name = "Student4", FName = "Father4", Age = 23 });

  • Create an object of XmlSerializer class which will decide the type of data that is to be written (list of person here).
  • Create a stream having FileMode Create and FileAccess Write.
  • At the last serialize the list to stream and stream will write it to xml file.

Read data from XML file:


To read data from XML file we use Deserialize method that deserialize the xml document contained by stream. It takes only one parameter i.e. our stream.


List<Person> accessedData = new List<Person&gt
XmlSerializer serializer = new XmlSerializer(typeof(List<Person>));
using (FileStream stream = new FileStream(Environment.CurrentDirectory + "\\file.xml", FileMode.Open, FileAccess.Read))
{
    accessedData = serializer.Deserialize(stream) as List<Person>;
}
dataGridView1.DataSource = accessedData;

In above code
  • Declare a list of person that will hold deserialized data.
  • Create an object of XmlSerializer class which will decide the type of data that is to be read (list of persons here).
  • Create a stream having FileMode Open and FileAccess Read.
  • At the last deserialize the data and convert them to List<Person>.
After successfully deserialize the data in list, i am bind that list to datagridview. When i run the project, my datagridview look like following screenshot:


We can read more about Environment.CurrentDirectory

Tuesday, July 2, 2013

How to use CompareValidator Control in ASP.NET

Introduction
The CompareValidator control is used to compare the value entered by a user into one input control with the value entered into another input control or with an already existing value. The CompareValidator control exists within the System.Web.UI.WebControls namespace.

Operator Properties of the CompareValidator Control
Equal : Checks whether the compared values are equal .

NotEqual : Checks that controls are not equal to each other.

GreaterThan : Checks the greater than relationship.

GreaterThanEqual : Checks for a greater than or equal to relationship.

LessThan : Checks for a less than relationship.

LessThanEqual : Checks for a less than or equal to relationship.

DataTypeCheck : Compare dataTypes between the value entered into the data-entry .

The Type property is used to specify the data type of both the comparison values, where String is the default type. Both values are automatically converted to the string data type before the comparison operator is performed . The different data types that can be use are as follows

String : A string data type.
Integer : An Integer data type.
Double : A double data type.
Date : A date data type.
Currency : A currency data type.
Public Properties of the CompareValidator class

ControlToCompare : Obtains or sets the data entry , which has to be compared with the data-entry control.
Operator : Obtains or sets the comparison operation to perform.

ValueToCompare: Obtains or sets a constant value to compare with the value entered by a user in the data entry control being validated.

Example


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>





Enter password :
 
 
<asp:TextBox ID="pwd" runat="server"></asp:TextBox>
<br />
<br />
Re-Enter:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<asp:TextBox ID="repwd" runat="server"></asp:TextBox>
<asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="pwd" ControlToValidate="repwd" ForeColor="Maroon">Password does not match</asp:CompareValidator>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Check Comparison" />




 
 
</div>
</form>
</body>
</html>
Output
comparevalidator

© Copyright 2013 Computer Programming | All Right Reserved