Export GridView Control With its Data to a Image file

Last post 01-16-2009 7:42 AM by divyeshdaivagna. 5 replies.

Sort Posts:

  • Export GridView Control With its Data to a Image file

    01-12-2009, 12:46 AM

     Hello Friends,

    plz help me out in dis

    I m havin a grid view control with dynamic data on an aspx page and i want to export whole gridview with its data to an image file eg:

    jpg,bmp etc..l..

    Plz friends tel me whether dis ispossible or not n if it is possible plz guide me through its very urgent...

    Any help wil be considered a lot 

     

    Yours Sincerely,

    Divyesh

  • Re: Export GridView Control With its Data to a Image file

    01-12-2009, 1:30 AM
    • Contributor
      4,209 point Contributor
    • SyntaxC4
    • Member since 07-13-2007, 2:25 PM
    • Guelph, Ontario
    • Posts 692

    Hi divyeshdaivagna,

    Try looking at this related post: http://forums.asp.net/t/1369200.aspx

    Hope this helps.

    *** REMINDER ***
    If you find this post useful, Please click the 'Mark as Answer' Button.

    *** DISCLAIMER ***
    All Code is provided AS IS.
  • Re: Export GridView Control With its Data to a Image file

    01-12-2009, 1:52 AM
    • Member
      86 point Member
    • jawahars
    • Member since 04-28-2008, 2:27 PM
    • Chennai,Tamilnadu,India
    • Posts 58

     Hi,

     

    Its possible only,

    try the following...

    Step 1:  Download the DLL UrlScreenShot.dll and give reference to that DLL

    Step2:   have a new page contains the grid to print(eg:grid.aspx)(working as a background process)

    step3:   write the following code in the page (eg:page1.aspx)  button click event

    using System;
    using System.Web;

    using be.taiki.UrlScreenshot;

    public partial class page1 : System.Web.UI.Page
    {
       public string ScreenshotFullLength(string Url,string fname)
        {
            UrlScreenshot Shot = new UrlScreenshot(Url);
            int newHeight = (Shot.Bitmap.Width / 400) * Shot.Bitmap.Height;
            Shot.Resize(400, newHeight);

            string Filename = LazyAssFilename();
            //Shot.Bitmap.Save(Server.MapPath(Filename));
            Shot.Bitmap.Save("D:/" + fname);

            return Filename;
        }
        private string LazyAssFilename()
        {
            return Guid.NewGuid().ToString().Replace("-", "") + ".jpg";
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            ScreenshotFullLength("http://localhost:2462/UrlScreenshot-Example/grid.aspx", "grid.jpg");

        }
    }

     

     

    conclusion:

    after u click the button the image with that grid is stored in the path as u specified(here in D Drive) as a image.

     

    -- "Mark As Answer" if my reply helped you --
    Thanks,
    Jawahar
    Lets screw the Technolgies.
  • Re: Export GridView Control With its Data to a Image file

    01-13-2009, 5:31 AM

    Hi Jawahar thanks 4 ur reply But yaar i need to export only the grid view n not the whole page.

    Can u help me out on dat

    thankin u

    Divyesh 

  • Re: Export GridView Control With its Data to a Image file

    01-13-2009, 7:22 AM
    Answer
    • Member
      86 point Member
    • jawahars
    • Member since 04-28-2008, 2:27 PM
    • Chennai,Tamilnadu,India
    • Posts 58

     Have one more page(page2) that contains the same grid(grid only) as like in the current page(page1)

     While u click the button give the url of page2 then the grid only will become image.

    if u have doubt send ur code or i will send u the sample code!!!!!!!!!!!!!!!!!!!

     

     

    -- "Mark As Answer" if my reply helped you --
    Thanks,
    Jawahar
    Lets screw the Technolgies.
  • Re: Export GridView Control With its Data to a Image file

    01-16-2009, 7:42 AM

     Hi Jawahar,

     I m sending my code

    here is sample code of binding gridview on button click n i want to convert this gridview into an image file...

     

    Thanking you  ,

    Divyesh 

     
    Button Click Code

    protected void Button1_Click(object sender, EventArgs e)
    {
    conn = new SqlConnection(ConnectionString);
    cmd = new SqlCommand("select * from customermaster", conn);
    DataTable dt = new DataTable("dt");
    da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    Code of Aspx Page

    "form1" runat="server">
    "Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    "GridView1" runat="server">



     
Page 1 of 1 (6 items)