using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
protected void btnPrint_Click(object sender, EventArgs e)
{
ArrayList ID = new ArrayList(); //Declare new ArrayList
DateTime selectedDate1; //Set to DateTime
DateTime selectedDate2; //Set to DateTime
int userID = UserManager.GetUserID(HttpContext.Current.User.Identity.Name); //GetUserID
selectedDate1 = DateTime.Parse(this.txtDate1.Text.Trim()); //assign selectedDate value = textbox value
selectedDate2 = DateTime.Parse(this.txtDate2.Text.Trim()); //assign selectedDate value = textbox value
ID.Add(DataManager.GetMedicationListByDate(userID, selectedDate1, selectedDate2)); //add value into array
Response.Redirect("PDF.aspx?ID=" + ID); // transfer to a new page
}
ok now i want to transfer the values to the PDF. page which need to get the values and display on each page in PDF. I need to get the querystring which i set as an array but i dont pretty know how to do it so i did some research but still not sure zzzzzz. My code goes like this
using System;
using System.IO;
using System.Collections;
using System.Linq;
using TallComponents.PDF.Layout;
using TallComponents.PDF.Layout.Paragraphs;
using TallComponents.PDF.Layout.Brushes;
using TallComponents.PDF.Layout.Fonts;
protected void Page_Load(object sender, EventArgs e)
{
// create document
Document doc = new Document();
// add a section
Section section = doc.Sections.Add();
section.PageSize = PageSize.A4;
int medicationListID = int.Parse(Request.QueryString["ID"]); // error here "Input string was not in a correct format."
if (int.Parse(Request.QueryString["ID"]) != null)
{
int[] selectedIDs = ID.Cast
foreach (int intValue in selectedIDs)
{
//get the data of the medication according to ID
MedicationList medicationList = DataManager.SelectMedicationList(medicationListID);
//start on a new page
section.StartOnNewPage = true;
//Does all my actions displaying
}//end of foreach statement
}//end of IF statement
// save the PDF directly to the browser
doc.Write(Response);
}//end of pageload
can anyone help me with this? i need to make it working asap.
VulpesPosted Aug 25, 2011, 6:49 AM
Sam HobbsPosted Aug 26, 2011, 6:47 PM
Also note that Vulpes is using String.Split, which is what I was also suggesting. For dong the reverse, the concatenation, the following uses String.Join.
for (int i = 0; i < ID.Count; i++)
sa[i] = ID[i].ToString();
Response.Redirect("PDF.aspx?ID=" + string.Join("_", sa)); // transfer to a new page
Toh Zuan YiPosted Aug 26, 2011, 2:55 AM
Sam HobbsPosted Aug 25, 2011, 11:31 PM
Toh Zuan YiPosted Aug 25, 2011, 10:21 PM
Mr.Vulpes, i have a question to ask for your solution. a simple one though, is the
for(int i = 0; i < items.Length; i++) selectedIds[i] = int.Parse(items[i]);
does this mean that int.parse(items[i]) is each of the selected IDs? example if the querystring received 3 IDs(1, 2 and 3), this sentence would be to seperate them to each ID? if so, how can i put that int.parse(items[i]) to use? can i do it like this?
int medicationID = int.Parse(items[i]);
and then using my datamanager to get the data according to their ID
MedicationList medicationList = DataManager.SelectMedicationList(medicationID);
appreciate your replies
Sam HobbsPosted Aug 25, 2011, 1:41 PM