how to bind grid view, show it and then generate pdf? - c#

I have a page on which user select a date range and submit the form. I am picking data as per date range and then binding it to the gridview. Since I have to also generate pdf just after binding I am using response.write to write the generated pdf file to the user. But the problem is that the gridview never changes. The moment I stops execution after gridbind(return;), the gridview binds properly. After struggling for some time i found out it is happining due to response.write and response.end statement which is used for writing the file.
My question is how to do these two task back to back? so that when user submit the form he sees the gridview with all data and also the file gets downloaded.
right now after gridbinding I generate 1 more link to the generated pdf but the client wants that it should be done in one go instead of 2 .

you can achieve this using two ways
show your data to user and set interval in javascript lets say wait for 1 min and then postback page to download PDF.
(RECOMMENDED)create another page say FileDownloader.aspx and open that page in new window using javascript. you can share your data between pages using session, disk, db whatever suits you best.

Related

Returning the gridview to its original vertical location after the rowediting postback

Using a combination of asp.net, jQuery, and c# and stored procedures.
I have successfully created a gridview, which I then apply jQuery datatables plugin to provide text column filtering (I disabled most of the other datatables function/settings off)).
The Gridview works as expected and when I make use of the RowEditing and RowUpdating events also, IE the editable fields update nicely.
If the user clicks and edits, then clicks the update link, the database is updated and the page reloads. now if that person has scrolled down say record 50 (half way down for instance) in order to locate and then edit that record, then after the page refresh, the user then has to scroll back down to find that same record.
I'm trying to find a way of returning the user to the same location (record) that they had just edited before the page refresh after the page refresh.
I found a very simple solution to my problem with out a load of coding and it turned out to be MaintainScrollPositionOnPostback="True" page directive.
Unless I've misunderstood; your dilemma is nothing to do with gridviews etc, and is all to do with merely maintaining page scroll position on post-back... have a read of this JavaScript solution from the 4 guys
P.S. Google is your friend

Printing a separate report webpage without displaying in ASP.NET

This is somewhat related to my previous printing question re: remote printing, which I resolved with help here at work. This new situation likely has a simple answer as well, but I have yet to discover it.
To simplify, I have two webpages written in ASP.NET with C# codebehind, which we can call page1.aspx and page2.aspx.
The first page, page1.aspx, is a simple search tool that opens a database and returns a list of reports matching the search criteria into a gridview. The second page, page2.aspx, displays a report in the web browser, given the report ID as a query variable (which I have working). This page is also pre-formatted to be printer friendly.
On page1.aspx, in my gridview, I have two buttons for each row labeled "View" and "Print". The "View" button will retrieve the appropriate order number for the corresponding row, and page2.aspx will load the report based on the order number (again passed as a query variable).
For the "Print" button, however, I would like to print. That is, when the user clicks the button, instead of the page loading onto the screen, I would like for the Print dialog to pop up and allow the user to print the report directly to the printer (since they are able to view the report using the separate button if they should so desire).
I would load page2 into an iframe, probably separately and have the page call a JavaScript print when loaded, or call focus on the iframe and then print on the same object.
You could load the page with a new call, or just load it when page1 loads in the background.
You would, of course, make the iframe hidden from view.

Gridview column that changes when required (ASP.NET)

I need to have a GridView listing all invoices of an account. Each account can have a PDF generated for that account, which isn't done instantly - so I need a gridview column to update the user of the progress of this conversion - i.e. 'In Progress'.
Then, when the conversion is done the cell's text should change to a hyperlink to the PDF file.
I know it's a very vague question in regards to monitoring the state of the PDF, but I'd just like to know if AJAX would be a solution and what controls I would use.
Hmm... So there's a gridview with several rows (accounts), and each account may have its Pdf state changed at any time, and the link cell should be refreshed immediately (upon a Pdf state change)?
Try searching for "web methods" + "web services" + "asynchronous" and check if it's what you are looking for.
If you can, using a control like Telerik's RadControls Grid, which has Webservice binding, can do the work for you, continuously refreshing the data as it changes: http://demos.telerik.com/aspnet-ajax/controls/examples/integration/aspajaxgridapplication/defaultcs.aspx?product=grid

Ways to detect changed account/no account found in ASP.NET/C#

I have an ASP.NET page where at the top of the page is a search box. There are 2 text boxes - one is an autocomplete extender for the Name on a database, and one is just inputting the ID.
The page features DetailsViews and GridViews primarily, and even when no account has been searched for, these display blank data which is not ideal. I sort of fixed this by using if (IsPostBack), encasing the elements in a placeholder and setting it to visible only if the page ispostback. But this doesn't cover if the user types in an incorrect ID.
Also, some accounts have huge amounts of data inside the GridView's. I had an issue where because I have no way of detecting when a data source's rows has changed, I end up binding whenever the page loads (Page_Load method). I've come to realise this is simply very bad - there are lots of times when the user can click various things in the page and have the page postback, and it takes an eternity to load each time I click something for accounts with lots of data.
Anyway, my question is essentially two-fold but I have a feeling the solution will be similar:
1: How can I detect when there are no accounts returned when searching, and disable the Grids/Detailsviews and show an error message?
2: How can I figure out when the user searches for another account and only rebind the grids after that has happened?
Thanks
This method is very ugly but it'll get the work done.
1) To Check whether there are no records; after the AutoComplete Extenders Webservice is called if no record is returned put some value in Session like
Session["NoData"]=true;
if Records are found then;
Session["NoData"]=false;
after the webservice is called do ajax request to check that session & on the basis of value do what you want.
2) You can achieve this also by following the above option.

displaying an image from a bitmap variable using codebehind

I wish to create a very simple web app that simply displays an Image(s) from a database based upon either a date (from a calendar click event) or from a keyword search, getting the image(s) is no problem but I don't know how to display the resulting image. Preferably I would like to display the image in a table or grid or whatever, adjacent to the Calendar and TextBox on the same page that I used to get the search critera
So how to I stream an image to a page from a codebehind bitmap variable ?
Edit:
The database is a cloud database, so databinding is out.
Take a look at the DynamicImageHandler for ASP.NET up on the CodePlex ASP.NET Futures site:
http://www.hanselman.com/blog/ASPNETFuturesGeneratingDynamicImagesWithHttpHandlersGetsEasier.aspx
If you don't have the physical file on hand, try using:
Response.OutputStream.Write(bitmapbuffer, bitmapbuffer.Length)
I've done this in the past to dynamically serve pdfs and tifs, and it works quite nicely. You'll need to set your img's src attribute to contain the information you need. This web site has an example close to what you are looking for:
http://www.jigar.net/articles/viewhtmlcontent3.aspx
This isn't a good idea, since you don't know when to release the resource.
Rather, create a page (or a page handler, etc, etc) which will take the parameters you need in the querystring to perform the lookup in the database to get the image.
Then, in the handler, you load your image from the database and then stream the bytes back through the page.
In the original page, you set the src attribute of the img tag to the other page, with the appropriate parameters.

Categories

Resources