Friday, February 24, 2012

GridView Show Footer And Header No Record in Grid

When No Record in Grid view at that time show Header and Footer.
only we add on Row in Dataset.

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>GridView Show Footer And Header No Record in Grid</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1>
<a href="http://aspdotnet-example.blogspot.com/">http://aspdotnet-example.blogspot.com
</a>
</h1>
<h1>GridView Show Footer And Header No Record in Grid</h1>
<asp:GridView ID="gridView" runat="server" AutoGenerateColumns="false" DataKeyNames="MetalId"
EmptyDataText="No Data Found." PageSize="10" CellPadding="4" ForeColor="#333333"
GridLines="None" Style="margin-right: 0px" AllowPaging="True">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="MetalName" HeaderText="GridView Name" ReadOnly="True"
SortExpression="MetalName" />
<asp:BoundField DataField="Status" ItemStyle-HorizontalAlign="Center"
 HeaderText="Is GridView Active?"
ReadOnly="True" SortExpression="Status" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</div>
</form>
</body>
</html>
GridViewNoRecord.aspx.cs 
using System;
using System.Linq;
using System.Web.UI.WebControls;
using System.Data;

public partial class GridViewNoRecord : System.Web.UI.Page

{

    LogicLayer objLogicLayer = new LogicLayer();

    protected void Page_Load(object sender, EventArgs e)

    {

        if (!Page.IsPostBack)
        {

            FillGridView();

        }

    }

    protected void FillGridView()

    {

        if (objLogicLayer.ListMetals().Tables[0].Rows.Count != 0)

        {

            gridView.DataSource = objLogicLayer.ListMetals();

            gridView.DataBind();

        }

        else

        {

            BuildNoRecords(gridView, objLogicLayer.ListMetals());

        }

    }
     public void BuildNoRecords(GridView gridView, DataSet ds)
    {

        try

        {

            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());

            ds.Tables[0].Rows[0][1] = "No Records Found.";

            gridView.DataSource = ds;

            gridView.DataBind();
}

        catch (Exception ex)

        {

        }

    }

}
GridView Show Footer And Header No Record in Grid

Friday, February 17, 2012

How to send mail using SMTP Mail in asp.net

using System;
using System.Web.Mail;

public class SmtpMailExample
{
public static void Main()
{
string FromSMTP = "from@asp.net";
string ToSMTP = "to@smtp.net";
string SubjectSMTP = "This is a SMTP Test Mail Example Message";
string BodySMTP = "Hi .";

SmtpMail.SmtpServer = "192.168.1.151";
SmtpMail.Send(FromSMTP, ToSMTP, SubjectSMTP, BodySMTP);
}
}

Tuesday, February 14, 2012

call system dll method csharp

call system dll method in csharp application.
in this example we are using User32.dll file.

Monday, February 6, 2012

How to Clear Browser Cache using Javascript ?

This very Common Problem facing web developer. whenever user updating style sheet.
they need to press (Ctrl + F5) for clear browser cache.
 
Now if you are using any JavaScript file  then give name like
for i.e 
JavaScriptFileName.js?Math.random() 
<script type="text/javascript" 
src="http://hostname.net/js/JavaScriptFileName.js?Math.random()">
</script>
 
 
this is solution for clear browser cache.

List View Drag and Drop Control using Jquery

 In this example two things are covered.
1. List View Drag and Drop Control using Jquery 
2. How to read data from XML ?
 dragNdrop.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="dragNdrop.aspx.cs" 
Inherits="DragItemInListViewASPNET.dragNdrop" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="JQuery/jquery-ui.css" rel="stylesheet" type="text/css" />
    <script src="JQuery/jquery-1.4.4.min.js" type="text/javascript"></script>
    <script src="JQuery/jquery-ui.min.js" type="text/javascript"></script>
    <style type="text/css">
        #DragableTable1, #DragableTable2
        {
            list-style-type: none;
            border-right: #669999 2px solid;
            padding-right: 5px;
            border-top: #669999 2px solid;
            padding-left: 5px;
            float: left;
            padding-bottom: 0px;
            margin: 3px;
            border-left: #669999 2px solid;
            width: 160px;
            padding-top: 5px;
            border-bottom: #669999 2px solid;
        }
        #DragableTable1 li, #DragableTable2 li
        {
            border-right: #000 1px solid;
            padding-right: 2px;
            border-top: #000 1px solid;
            padding-left: 2px;
            font-size: 15px;
            margin-bottom: 5px;
            padding-bottom: 2px;
            border-left: #000 1px solid;
            width: 156px;
            cursor: pointer;
            padding-top: 2px;
            border-bottom: #000 1px solid;
            background-color: #eee;
        }
    </style>
    <script type="text/javascript">
        $(function () {
            $("#DragableTable1, #DragableTable2").sortable({
                connectWith: ".connectedDragableTable"
            }).disableSelection();
        });

        $(document).ready(function () {
            $("li").dblclick(function () {
                $(this).closest('li').remove();
            });
        });   
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <h1>
        <b>List view Drag and Drop Example</b></h1>
    <br />
    <div>
        <asp:ListView ID="ListView1" runat="server">
            <LayoutTemplate>
                <ul id="DragableTable1" class="connectedDragableTable">
                    <asp:PlaceHolder runat="server" ID="itemPlaceholder">
</asp:PlaceHolder>
                </ul>
            </LayoutTemplate>
            <ItemTemplate>
                <li class="ui-state-default">
                    <%# Eval("Dragvalue1") %></li>
            </ItemTemplate>
        </asp:ListView>
        <asp:ListView ID="ListView2" runat="server">
            <LayoutTemplate>
                <ul id="DragableTable2" class="connectedDragableTable">
                    <asp:PlaceHolder runat="server" ID="itemPlaceholder">
</asp:PlaceHolder>
                </ul>
            </LayoutTemplate>
            <ItemTemplate>
                <li class="ui-state-highlight">
                    <%# Eval("Dragvalue2") %></li>
            </ItemTemplate>
        </asp:ListView>
    </div>
    </form>
</body>
</html>
dragNdrop.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml;
using System.Data;
namespace DragItemInListViewASPNET
{
    public partial class dragNdrop : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            XmlDocument xmlDocument = new XmlDocument();
            using (DataTable objListView1 = new DataTable())
            {
                objListView1.Columns.Add("Dragvalue1", Type.GetType("System.String"));
 xmlDocument.Load(AppDomain.CurrentDomain.BaseDirectory + "/XmlFile/ListViewData1.xml");
 XmlNodeList xmlNodeList = xmlDocument.SelectNodes("root/data[@open='1']");
                foreach (XmlNode xmlNode in xmlNodeList)
                {
                    DataRow dr = objListView1.NewRow();
                    dr["Dragvalue1"] = xmlNode.InnerText;
                    objListView1.Rows.Add(dr);
                }
                ListView1.DataSource = objListView1;
                ListView1.DataBind();
            }

            XmlDocument xmlDocument2 = new XmlDocument();
            using (DataTable objListView2 = new DataTable())
            {
                objListView2.Columns.Add("Dragvalue2", Type.GetType("System.String"));
xmlDocument2.Load(AppDomain.CurrentDomain.BaseDirectory + "/XmlFile/ListViewData2.xml");
 XmlNodeList xmlNodeList2 = xmlDocument2.SelectNodes("root/data[@open='1']");
                foreach (XmlNode xmlNode in xmlNodeList2)
                {
                    DataRow dr = objListView2.NewRow();
                    dr["Dragvalue2"] = xmlNode.InnerText;
                    objListView2.Rows.Add(dr);
                }
                ListView2.DataSource = objListView2;
                ListView2.DataBind();
            }
        }
    }
}
ListViewData1.xml
<?xml version="1.0" encoding="utf-8" ?>
<root>
  <data open="1">drag and drop element 1</data>
  <data open="1">drag and drop element 2</data>
  <data open="1">drag and drop element 3</data>
  <data open="1">drag and drop element 4</data>
  <data open="1">drag and drop element 5</data>
  <data open="1">drag and drop element 6</data>
  <data open="1">drag and drop element 7</data>
</root>

where clause in asp.net Linq

 This Linq example show you how to use where clause with array

Saturday, February 4, 2012

How to create Chart in asp.net ?

Create Chart control in asp.net
 
 Chart.aspx
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Chart.aspx.cs"
Inherits="Chart" %>

<%@ Register Assembly="System.Web.DataVisualization, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35"
Namespace="System.Web.UI.DataVisualization.Charting"
TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ASP.NET Chart Control Example</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h1><b>ASP.NET Chart Control Example</b></h1>
<asp:Chart ID="ChartAspnet" runat="server" Height="400px" Width="500px">
<Series>
<asp:Series Name="SeriesASPNET" ChartType="Column" ChartArea="ChartAreaASPnet">
</asp:Series>
<asp:Series Name="SeriesASPNET1" ChartType="Column" ChartArea="ChartAreaASPnet">
</asp:Series>
 
</Series>
 
<ChartAreas>
 
<asp:ChartArea Name="ChartAreaASPnet">
 
</asp:ChartArea>
 
</ChartAreas>
 
</asp:Chart>
 
</div>

 
</form>
</body>
</html>
ASPdotNET-Example