public void GetLastTxn(int day) { try { Reply objRes = new Reply(); // send request using (WebClient client = new WebClient()) { if (Session["Role"].ToString().Contains("admin")) { perameter = "all##" + day; } else { perameter = Session["Role"].ToString() + "#" + Session["Location"].ToString() + "#" + day; } client.Headers[HttpRequestHeader.ContentType] = "text/json"; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; string JsonString = JsonConvert.SerializeObject(perameter); EncRequest objEncRequest = new EncRequest(); objEncRequest.RequestData = AesGcm256.Encrypt(JsonString); string dataEncrypted = JsonConvert.SerializeObject(objEncRequest); string result = client.UploadString(URL + "/GetLastTransactionDetail", "Post", dataEncrypted); // GetDashBoardDetail |GetLastTransactionDetail EncResponse objResponse = JsonConvert.DeserializeObject <EncResponse>(result); objResponse.ResponseData = AesGcm256.Decrypt(objResponse.ResponseData); //objRes = JsonConvert.DeserializeObject<Reply>(objResponse.ResponseData); //DataContractJsonSerializer objDCS = new DataContractJsonSerializer(typeof(Reply)); //MemoryStream objMS = new MemoryStream(Encoding.UTF8.GetBytes(objResponse.ResponseData)); //objRes = (Reply)objDCS.ReadObject(objMS); Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer(); json.NullValueHandling = NullValueHandling.Ignore; StringReader sr = new StringReader(objResponse.ResponseData); Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr); objRes = json.Deserialize <Reply>(reader); LastTransaction = new DataSet(); LastTransaction.Tables.Add(); LastTransaction.Tables[0].Columns.Add("Sno"); LastTransaction.Tables[0].Columns.Add("Date"); LastTransaction.Tables[0].Columns.Add("LastTransaction"); DataRow drow; int iDSIterator = 1; DateTime DataTransaction; if (objRes.res == true && objRes.DS.Tables[0].Rows.Count > 0) { for (int i = 0; i <= 9; i++) { drow = LastTransaction.Tables[0].NewRow(); drow["Sno"] = i + 1 + Environment.NewLine; DataTransaction = DateTime.Now.AddDays(-iDSIterator); drow["Date"] = DataTransaction.ToString("dd-MM-yyyy"); try { bool IsFound = false; int iCount = 0; while (iCount < objRes.DS.Tables[0].Rows.Count)//handled index out of bound exception// { if (DataTransaction.ToString("dd-MM-yyyy").Contains(objRes.DS.Tables[0].Rows[iCount]["txn_dt"].ToString())) { IsFound = true; drow["Date"] = DataTransaction.ToString("dd-MM-yyyy"); try { drow["LastTransaction"] = Convert.ToInt32(objRes.DS.Tables[0].Rows[iCount]["total_transaction"]); } catch (Exception ex) { drow["LastTransaction"] = "0"; } break; } iCount++; } if (IsFound == false) { drow["Date"] = DataTransaction.ToString("dd-MM-yyyy"); drow["LastTransaction"] = "0"; } } catch (Exception ex) { lbl_txn_error.Text = "" + ex; drow["Date"] = DataTransaction.ToString("dd-MM-yyyy"); drow["LastTransaction"] = "0"; } iDSIterator++; LastTransaction.Tables[0].Rows.Add(drow); if (LastTransaction.Tables[0].Rows.Count >= 10) { break; } } } else { for (int i = 0; i < day; i++) { drow = LastTransaction.Tables[0].NewRow(); drow["Sno"] = i + 1; if (i == 0) { DataTransaction = DateTime.Today; } else { DataTransaction = DateTime.Today.AddDays(-i); } drow["Date"] = DataTransaction.ToString("dd-MM-yyyy"); drow["LastTransaction"] = "0"; LastTransaction.Tables[0].Rows.Add(drow); } } } } catch (Exception ex) { Response.Write("<script type='text/javascript'>alert('catch error : " + ex.Message + " ')</script>"); } finally { dataListTransaction.DataSource = LastTransaction; dataListTransaction.DataBind(); } }