上方廣告

Lady Kukki 手作糖霜餅乾

2009年8月29日 星期六

抓取QueryString上字串(參數)

//假設URL參數字串為
//index.aspx?id=aaa&email=hh@gmail.com&id2=bbb&email=cc@hotmail.com

for (int i = 0; i < Page.Request.QueryString.Count; i++)
{
    if (Page.Request.QueryString.AllKeys.GetValue(i).ToString().StartsWith("id"))
    {
        rowid = Page.Request.QueryString.AllKeys.GetValue(i).ToString().Replace("id", "");
        if (strParameter == "")
        {
            if (!string.IsNullOrEmpty(rowid)) strIndex += rowid;
            strParameter = " ( id=" + string.Format("@id{0} ", rowid) + 
      " and email=" + string.Format("@email{0} ", rowid) + " ) ";
        }
        else
        {
            if (!string.IsNullOrEmpty(rowid)) strIndex += "," + rowid;
            strParameter += " OR ( id=" + string.Format("@id{0} ", rowid) +
       " and email=" + string.Format("@email{0} ", rowid) + " ) ";
        }
    }
}