Sunday, June 17, 2012

How to get NIC Address or Machine Address in C# Programming using .NET technology

Step1: Add a refrence(System.Management) in Refrences Folder

Step2: use these "name space system" in code windows

using System.Management;
using System.Runtime.Remoting;
using System.Security.Permissions;
using System.Net.NetworkInformation;
using System.Collections;
using System.ComponentModel;

Step3: make a private function as GetMacAddress() and call it on an event;

private string GetMacAddressNew()
        {
            string macAddresses = "";

            foreach (NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces())
            {
                if (nic.OperationalStatus == OperationalStatus.Up)
                {
                    macAddresses += nic.GetPhysicalAddress().ToString();
                    break;
                }
            }
            return macAddresses;
        }
That's it all.

Thursday, June 7, 2012

Paging in Data List C# with .NET Code

On Form View Take
"DataList" and Name it as DataList1
"SqlDataSource" and Named it  as SqlDataSource1
Take a Label and named it as "lblCurrentPage"
take 2 button one for next and one for previous

With SqlDataSource
configure it with database and table

With grid view
set the "RepeatColumn" property and height width property

On Code window
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.Configuration;
using System.Data.SqlClient;

public partial class DataListPaging : System.Web.UI.Page
{
    static int CurrentPage;
    protected void Page_Load(object sender, EventArgs e)
    {
        items();
    }
    protected void items()
    {
        PagedDataSource objDs = new PagedDataSource();
        DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        objDs.DataSource = dv;
        objDs.AllowPaging = true;
        objDs.PageSize = 6;
        objDs.CurrentPageIndex = CurrentPage;
        lblCurrentPage.Text = "Page:" + (CurrentPage + 1).ToString() + " Of " + objDs.PageCount.ToString();
        back1.Enabled = !objDs.IsFirstPage;
        next1.Enabled = !objDs.IsLastPage;
        DataList2.DataSource = objDs;
        DataList2.DataBind();

    }

    protected void next1_Click(object sender, EventArgs e)
    {
        try
        {

            CurrentPage += 1;
            items();
        }
        catch (Exception)
        {        }
    }
    protected void back1_Click(object sender, EventArgs e)
    {
        try
        {
            CurrentPage -= 1;
            items();
        }
        catch (Exception)
        {    }
    }
  
}