visual studio 2010




ASP.NET 3 Tire Architecture using stored procedure.

Three tire architecture in asp.net.

Three tire architecture in asp.net using stored procedure.



How to start  sql server 2008
Start-àAll Program-à Microsoft SQL SERVER 2008(CLICK)
Then , Select SQL SERVER MANAGEMENT STUDIO
As shown below figure


A new windows open -àconnect to server
Please Enter Login=sa(as a default, awalys)
                    Password=password (which you provide during installation).
Then click Connect.



Finally sql server 2008 is connected , as shown below figure






How to CREATE DATABASE in SQL SERVER 2008 ?
Step-1
In E:/ drive just I copy the database as shown below


Step-2
To attach a database
  1. Connect to the Database Engine.
START-àALL PROGRAM-àSQL SERVER 2008--àSQL SERVER MANAGEMENT STUDIO
Then  a new wizerd open as shown below


Please Enter Login=sa(as a default, awalys)
                    Password=password (which you provide during installation).
Then click on OK.


Step-3
  1. From the Standard bar, click New Query.AS shown below figure

Then
  1. Use the Create Data Base statement with the FOR ATTACH close.
CREATE DATABASE MYCreateDatabase
    ON (FILENAME = 'E:\MySQLServer\ MYCreateDatabase _Data.mdf'),
    (FILENAME = 'E:\MySQLServer\ MYCreateDatabase _Log.ldf')
    FOR ATTACH;
Copy and paste the above example into the query window and click Execute.
This example attaches the files of the MYCreateDatabase database and renames the database to MYCreateDatabase.


As shown above .finally we got following screen.


Step-4
See database is create in sql server 2008.







How to copy Web Site in new Asp.Net?
                     0r 
How to: Copy a Project in new web site
Step-1

START-àALL PROGRAM-àMicrosoft Visual STUDIO 2010, then a new

windows open ,
 after that file-àNew-àweb site(Click on it)
Choose ASP.NET Web site.

Step-2
A new web site windows open click on  ASP.NET Web Site  Visual C# , Give  application name(EducationApplication) ,

Finally click on OK button , AS FOLLOW

After that a new windows open as follow,
 Check top must side of vs2010 EducationApplication-Microsoft Visual Studio
   The click on  WebSiteàCopy Web Site… click on it.

Then new windows open as follow

Click on Connect window is open ,

Choose file location & Click on open, as follow




After that
Select all Remot Web Site & cope to Source web site.




Finally click on Remot Web Site & Disconnect, new alert windows open say Yes , as follow

Build and Save and find out Error.

Note:- Error means connectionstring ,file not found etc





How to add SQL SERVER 2008 Database in your asp.net application
Step-1
Create new web application (DataToolExample.aspx).
After that left side of application, click on Server Explore---àclick on Connect To Database, Than following windows open



Step-2
Server Name= which you provide during installation of SQL SERVER 2008 .

Use SQL Server Authectication Please Enter Login=sa(as a default, awalys)  Password=password (which you provide during installation).

After that Select or Enter a database name from Drop down List :-here see you have created database name displaed in dropdown list for example NORTHWND_DB.

Finally click Test Connection.

CLICK OK FOLLOWING WINDOWS OPEN


Then popup display click on OK button.

Step-3
Finally NORTHWND_DB add in your project.You can confirm, under Data Connection=>NORTHWND_DB


Thank You.




How to install IIS IN Windows 7.
Click on Start-àControl Panel

Click on (Program)Uninstall a program , then new windows open and find left hand side ---->click on
    Turn Windows Features On Or Off

Expand(click on +) Internet Information Services and select the check box as per following screen


Then click Ok .it will display a wait windows , after that it is ask for Restart the system, then restart the system (if you not restart the system then effect will not apply).
Finally open browser & type  http://localhost or localhost , then following screen open.



Or (other way to check iis is installed or not in your system)

Click on START-àin search type inetmgr then following windows open



After that press Enter following windows open


That all IIS install in your system.
thank you.




Here I am explain how to create virtual directory & publish the web side, so we can run our .net application in other system.
Click on start select Microsoft Visual Studio 2010(right click & open with Administrator) and create new project.
After that take a Button & lable as shown above screen.
Double click on Button & write following code for display message on label.
textbox1.text="hi";

Right click on check application --> click on package/publish setting following windows open
























<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Home.master" AutoEventWireup="true" CodeFile="VehicleAllocation.aspx.cs" Inherits="Admin_VehicleAllocation" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <style type="text/css">
        .style2
        {
            width: 100%;
        }
        .style3
        {
        }
        .style11
        {
            width: 92px;
        }
        .style13
        {
            width: 368px;
        }
        .style14
        {
            width: 87px;
        }
    </style>
</asp:Content>



<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">

    <asp:ValidationSummary ID="ValidationSummary1" runat="server" Font-Bold="True"
        ForeColor="#CC3300" ValidationGroup="vg1" Width="486px" />
<fieldset class="register">
                            <legend>Vehicle Allocation</legend>
    <table class="style2">
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                Client Name:</td>
            <td class="style13">
<asp:DropDownList ID="ddlClientName" runat="server" Height="19px" Width="151px"
> 
<asp:ListItem>--Select Client Name--</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="RequiredFieldValidator101" runat="server"
ControlToValidate="ddlClientName"
ErrorMessage="Select Client Name."
InitialValue="--Select Client Name--"
ValidationGroup="vg1"
Font-Bold="True"
ForeColor="#CC3300">*</asp:RequiredFieldValidator>
                &nbsp;</td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                Vehicle Name:</td>
            <td class="style13">
             <asp:DropDownList ID="ddlVehicleName" runat="server" Height="16px" Width="151px">
                        <asp:ListItem>--Select Vehicle Name--</asp:ListItem>
                    </asp:DropDownList>
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator102" runat="server"
                                                 ControlToValidate="ddlVehicleName"
                                                 ErrorMessage="Select Vehicle Name."
                                                 ToolTip= "Please Select Vehicle Name is required."
                                                 ValidationGroup="vg1"
                        InitialValue="--Select Vehicle Name--" Font-Bold="True"
                    ForeColor="#CC3300">*</asp:RequiredFieldValidator>

                &nbsp;</td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                Shift Name:</td>
            <td class="style13">
             <asp:DropDownList ID="ddlShiftName" runat="server" Height="16px" Width="151px">
                        <asp:ListItem>--Select Shift Name--</asp:ListItem>
                        <asp:ListItem>Morning</asp:ListItem>
                        <asp:ListItem>AfterNoon</asp:ListItem>
                        <asp:ListItem>Evening</asp:ListItem>
                        <asp:ListItem>Night</asp:ListItem>
                    </asp:DropDownList>
                      <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
                                                 ControlToValidate="ddlShiftName"
                                                 ErrorMessage="Select Shift Name."
                                                 ToolTip= "Please Select Shift Name is required."
                                                 ValidationGroup="vg1"
                        InitialValue="--Select Shift Name--" Font-Bold="True"
                    ForeColor="#CC3300">*</asp:RequiredFieldValidator>

                &nbsp;</td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                Start Time:</td>
            <td class="style13">
            <asp:TextBox ID="txtStartTime" runat="server" Height="21px" Width="45px"
                        MaxLength="5"></asp:TextBox>
                &nbsp;<asp:DropDownList ID="DropDownList4" runat="server">
                        <asp:ListItem>AM</asp:ListItem>
                        <asp:ListItem>PM</asp:ListItem>
                    </asp:DropDownList>
                &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator104" runat="server"
                                                 ControlToValidate="txtStartTime"
                                                 ErrorMessage="Start Time is required."
                                                 ToolTip="Start Time is required."
                                                 ValidationGroup="vg1" Font-Bold="True"
                    ForeColor="#CC3300">*</asp:RequiredFieldValidator>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
                                                 ControlToValidate="DropDownList4"
                                                 ErrorMessage="Select  AM OR PM."
                                                 ToolTip= "Please Select AM OR PM is required."
                                                 ValidationGroup="vg1"
                        InitialValue="--Select AM/PM--" Font-Bold="True"
                    ForeColor="#CC3300">*</asp:RequiredFieldValidator>
                </td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                End Time:</td>
            <td class="style13">
            <asp:TextBox ID="txtEndTime" runat="server" MaxLength="5" Height="19px"
                    Width="44px"></asp:TextBox>
                    &nbsp;<asp:DropDownList ID="DropDownList5" runat="server" Height="16px"
                    Width="50px">
                        <asp:ListItem>AM</asp:ListItem>
                        <asp:ListItem>PM</asp:ListItem>
                    </asp:DropDownList>
                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
                                                 ControlToValidate="txtEndTime"
                                                 ErrorMessage="End Time is required."
                                                 ToolTip="End Time is required."
                                                 ValidationGroup="vg1" Font-Bold="True"
                    ForeColor="#CC3300">*</asp:RequiredFieldValidator>
                </td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                &nbsp;</td>
            <td class="style13">
            <asp:Button ID="btnAllocation" runat="server" Text="Allocation" Height="24px"
                        Width="112px" onclick="btnAllocation_Click" ValidationGroup="vg1" />
                </td>
        </tr>
        <tr>
            <td class="style14">
                &nbsp;</td>
            <td class="style11">
                &nbsp;</td>
            <td class="style13">
                <asp:Label ID="lblMessage" runat="server" Font-Bold="True" ForeColor="#CC3300"></asp:Label>
            </td>
            
        </tr>
       
        </table>
                        </fieldset>
    <fieldset class="register">
                            <legend>View Vehicle Allocation</legend>
                            <p>
                               <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None"
         DataKeyNames="vaid" AutoGenerateEditButton="True"
    AutoGenerateColumns="False" AllowPaging="True"
                        onpageindexchanging="GridView1_PageIndexChanging"
                        onrowcancelingedit="GridView1_RowCancelingEdit"
                        onrowdeleting="GridView1_RowDeleting" onrowediting="GridView1_RowEditing"
                        onrowupdating="GridView1_RowUpdating" PageSize="2"  >
            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#EFF3FB" />
            <EditRowStyle BackColor="#2461BF" />
            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="vaid" HeaderText="ID" ReadOnly="True" />
                <asp:TemplateField HeaderText="Client Name">
                    <ItemTemplate>
                        <%# Eval("ClientName")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtClientName" runat="Server" Text='<%# Eval("ClientName") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Vehicle Name">
                    <ItemTemplate>
                        <%# Eval("VehicleName")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtVehicleName" runat="Server" Text='<%# Eval("VehicleName") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Shift Name">
                <ItemTemplate>
                        <%# Eval("ShiftName")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtShiftName" runat="Server" Text='<%# Eval("ShiftName") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Start Time">
                 <ItemTemplate>
                        <%# Eval("StartTime")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtStartTime" runat="Server" Text='<%# Eval("StartTime") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                  <asp:TemplateField HeaderText="AM/PM">
                 <ItemTemplate>
                        <%# Eval("am")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtam" runat="Server" Text='<%# Eval("am") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                  <asp:TemplateField HeaderText="End Time">
                 <ItemTemplate>
                        <%# Eval("EndTime")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtEndTime" runat="Server" Text='<%# Eval("EndTime") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                  <asp:TemplateField HeaderText="PM/AM">
                 <ItemTemplate>
                        <%# Eval("pm")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtpm" runat="Server" Text='<%# Eval("pm") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                 <asp:TemplateField HeaderText="Action Date/Time">
                 <ItemTemplate>
                        <%# Eval("actiondate")%>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <asp:TextBox ID="txtactiondate" runat="Server" Text='<%# Eval("actiondate") %>'></asp:TextBox>
                    </EditItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Delete?">
                    <ItemTemplate>
                        <span onclick="return confirm('Are you sure to Delete?')">
                            <asp:LinkButton ID="lnBD" runat="server" Text="Delete" CommandName="Delete"></asp:LinkButton>
                        </span>
                    </ItemTemplate>
                </asp:TemplateField>
              
            </Columns>
                   
        </asp:GridView>
                            </p>
                        </fieldset>

</asp:Content>



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.Configuration;
using System.Data;
using System.Drawing;

public partial class Admin_VehicleAllocation : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            BindGridView();
            BindddlClientName();
            BindddlVehicleName();

        }
    }
    private void BindGridView()
    {

       
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from VehicleAllocation", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();

    }
    private void BindddlClientName()
    {
       
        SqlCommand cmd = new SqlCommand("select * from ClientRegistration", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);
    
        ddlClientName.DataSource = ds;
        ddlClientName.DataTextField = "fname";
        ddlClientName.DataValueField = "fname";
        ddlClientName.DataBind();
        ddlClientName.Items.Insert(0, "--Select Client Name--");
       
      
    }
    private void BindddlVehicleName()
    {
       
   
        SqlCommand cmd = new SqlCommand("select * from VehicleDetails", con);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlVehicleName.DataSource = ds;
        ddlVehicleName.DataTextField = "VehicleName";
        ddlVehicleName.DataValueField = "VehicleName";
        ddlVehicleName.DataBind();
        ddlVehicleName.Items.Insert(0, "--Select Vehicle Name--");
       
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        BindGridView();

    }
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        BindGridView();
    }
    protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int vaid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values["vaid"].ToString());

        //string username = GridView1.DataKeys[e.RowIndex].Values["UserName"].ToString();


        con.Open();
        SqlCommand cmd = new SqlCommand("delete from VehicleAllocation where vaid=" + vaid, con);
        int result = cmd.ExecuteNonQuery();
        con.Close();
        if (result == 1)
        {
            // Rebind the GridView control to show data after deleting.
            BindGridView();
            lblMessage.ForeColor = Color.Red;
            lblMessage.Text = " details deleted successfully";

        }
    }
    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int vaid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

        TextBox ClientNamee = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtClientName");
        TextBox VehicleNamee = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtVehicleName");
        TextBox ShiftNamee = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtShiftName");
        TextBox StartTimee = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtStartTime");
        TextBox amm = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtam");
        TextBox EndTimee = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtEndTime");
        TextBox pmm = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpm");


        con.Open();
        SqlCommand cmd = new SqlCommand("update VehicleAllocation set ShiftName='" + ShiftNamee.Text + "',StartTime='" + StartTimee.Text + "',am='" + amm.Text + "',EndTime='" + EndTimee.Text + "',pm='"+pmm.Text+"' where vaid=" + vaid, con);
        cmd.ExecuteNonQuery();
        con.Close();
        lblMessage.ForeColor = Color.Green;
        lblMessage.Text = " Details Updated successfully";
        GridView1.EditIndex = -1;
        BindGridView();
    }
    protected void btnAllocation_Click(object sender, EventArgs e)
    {
        try
        {
              con.Open();
            SqlCommand cmd = new SqlCommand("AddVehicleAllocation", con);
            cmd.CommandType = System.Data.CommandType.StoredProcedure;

            SqlParameter cname = new SqlParameter("@ClientName", System.Data.SqlDbType.NVarChar, 50);
            SqlParameter Vname = new SqlParameter("@VehicleName", System.Data.SqlDbType.NVarChar, 50);
            SqlParameter sname = new SqlParameter("@ShiftName", System.Data.SqlDbType.NVarChar, 50);
            SqlParameter stime = new SqlParameter("@StartTime", System.Data.SqlDbType.Time, 7);
            SqlParameter am = new SqlParameter("@am", System.Data.SqlDbType.VarChar, 10);
            SqlParameter etime = new SqlParameter("@EndTime", System.Data.SqlDbType.Time, 7);
            SqlParameter pm = new SqlParameter("@pm", System.Data.SqlDbType.VarChar, 10);
            SqlParameter actiondatee = new SqlParameter("@actiondate", System.Data.SqlDbType.DateTime);

            //cmd.Parameters.AddWithValue("@cid",);

            cmd.Parameters.AddWithValue("@ClientName", ddlClientName.Text);
            cmd.Parameters.AddWithValue("@VehicleName", ddlVehicleName.Text);
            cmd.Parameters.AddWithValue("@ShiftName", ddlShiftName.Text);
           cmd.Parameters.AddWithValue("@StartTime",txtStartTime.Text);
            cmd.Parameters.AddWithValue("@am", DropDownList4.Text);
           cmd.Parameters.AddWithValue("@EndTime",txtEndTime.Text);
            cmd.Parameters.AddWithValue("@pm", DropDownList5.Text);
            cmd.Parameters.AddWithValue("@actiondate", DateTime.Now);

            cmd.ExecuteNonQuery();
            lblMessage.Text = "Successfully Vehicle Allocation!!!!!!!!!!!";
            BindGridView();
            //lblMessage.Visible = true;
            ClearAll();
          
            con.Close();
            con.Dispose();
        }
        catch(Exception ex1)
        {
            Response.Write(ex1.Message);
        }
    }
    private void ClearAll()
    {
        ddlClientName.SelectedIndex = 0;
        ddlVehicleName.SelectedIndex = 0;
        ddlShiftName.SelectedIndex = 0;
        txtStartTime.Text = string.Empty;
        txtEndTime.Text = string.Empty;

    }
}




How to Generate PDF in asp.net




  <fieldset class="register">
                            <legend>Requiredment</legend>
                           
        1)EnableEventValidation=&quot;false&quot; in &lt;% Page %&gt;</p>
 
        2)public override void VerifyRenderingInServerForm(Control control) { /*
        Verifies that the control is rendered */ }</p>
   
        3)ImageButton1_Click (Code)</p>
  
        4)add Bin (itextsharp.dll)</p>

        Auto Genrate Col</p>

                       
                        </fieldset>
   
        <br />
   
        <asp:ImageButton ID="ImageButton1" runat="server"
            ImageUrl="~/Create Pdf/PDF.jpg" onclick="ImageButton1_Click"
                      />&nbsp;</p>
    <p>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
            CellPadding="4" DataKeyNames="BID" DataSourceID="SqlDataSource1"
            ForeColor="#333333" GridLines="None">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:BoundField DataField="BID" HeaderText="BID" InsertVisible="False"
                    ReadOnly="True" SortExpression="BID" />
                <asp:BoundField DataField="ClientName" HeaderText="ClientName"
                    SortExpression="ClientName" />
                <asp:BoundField DataField="VehicleCategoriesName"
                    HeaderText="VehicleCategoriesName" SortExpression="VehicleCategoriesName" />
                <asp:BoundField DataField="CostAsPerVCName" HeaderText="CostAsPerVCName"
                    SortExpression="CostAsPerVCName" />
                <asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
                <asp:BoundField DataField="StartKilomete" HeaderText="StartKilomete"
                    SortExpression="StartKilomete" />
                <asp:BoundField DataField="EndKilomete" HeaderText="EndKilomete"
                    SortExpression="EndKilomete" />
                <asp:BoundField DataField="TotalKilomete" HeaderText="TotalKilomete"
                    SortExpression="TotalKilomete" />
                <asp:BoundField DataField="TotalAmount" HeaderText="TotalAmount"
                    SortExpression="TotalAmount" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:TravelDBConnectionString %>"
            SelectCommand="SELECT * FROM [BillGeneration]"></asp:SqlDataSource>
    </p>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
using iTextSharp.text.html.simpleparser;

public partial class Create_Pdf_pdf : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public override void VerifyRenderingInServerForm(Control control)
    {
        /* Verifies that the control is rendered */
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        Response.ContentType = "application/pdf";
        Response.AddHeader("content-disposition", "attachment;filename=UserDetails.pdf");
        Response.Cache.SetCacheability(HttpCacheability.NoCache);
        StringWriter sw = new StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(sw);
        GridView1.AllowPaging = false;
        GridView1.DataBind();
        GridView1.RenderControl(hw);
        GridView1.HeaderRow.Style.Add("width", "15%");
        GridView1.HeaderRow.Style.Add("font-size", "10px");
        GridView1.Style.Add("text-decoration", "none");
        GridView1.Style.Add("font-family", "Arial, Helvetica, sans-serif;");
        GridView1.Style.Add("font-size", "8px");
        StringReader sr = new StringReader(sw.ToString());
        Document pdfDoc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);
        HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
        PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
        pdfDoc.Open();
        htmlparser.Parse(sr);
        pdfDoc.Close();
        Response.Write(pdfDoc);
        Response.End();
    }
}

Finaly add in Bin Folder-à

Refersh and run






No comments:

Tabs


Tab 1 content goes here

Tab 2 content goes here

Tab 3 content goes here
Multi-Tabbed Widget | DotNetIs