Toh Zuan Yi

Toh Zuan Yi

  • NA
  • 19
  • 24.1k

Getting query strings (array)

Aug 25 2011 5:44 AM
hi.. i have a question here i need help with. its almost the same as my post earlier, but no one replied to that post :( thats ok i have a simpler question here... i was asking how to request multiple querystrings, but it was actually one querystring("ID") but that "ID" contained more than 1 value. Example, i have a PDF.aspx page(page that converts to PDF) and Print.aspx page. On the Print.aspx, i get the values and store it in array(am i doing it correct?)

  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<int>().ToArray(); //Is this Correct?

  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.


Answers (6)