protected void btnVeiw_OnClick(object sender, EventArgs e) { try { string qry = ""; dtinfo.ShortDatePattern = "dd/MM/yyyy"; dtinfo.DateSeparator = "/"; if (rbtnICE.Checked == true) { lblGridTitle.Text = "Date: " + txtDateFrom.Text + " To: " + txtDateto.Text.ToString(); qry = "select IMID,DiaryNo,Session,SubDate as Date,AmtFor,DDDate,DDNO,Bank,Narration,Amt as Amount from FeeAC where SubDate Between '" + Convert.ToDateTime(txtDateFrom.Text, dtinfo) + "' and '" + Convert.ToDateTime(txtDateto.Text, dtinfo) + "' order by SubDate Desc"; } else if (rbtnIM.Checked == true) { lblGridTitle.Text = "IMID: " + txtIMID.Text.ToString() + " and Session: " + lblSessionHidden.Text.ToString(); qry = "select IMID,DiaryNo,Session,SubDate as Date,AmtFor,DDDate,DDNO,Bank,Narration,Amt as Amount from FeeAC where Session='" + lblSessionHidden.Text.ToString() + "' and IMID='" + txtIMID.Text.ToString() + "' order by SubDate Desc"; } else if (rbtnDiary.Checked == true) { lblGridTitle.Text = "Diary No. " + txtDiary.Text.ToString(); qry = "select IMID,DiaryNo,Session,SubDate as Date,AmtFor,DDDate,DDNO,Bank,Narration,Amt as Amount from FeeAC where DiaryNo='" + txtDiary.Text.ToString() + "' order by SubDate Desc"; } else if (rbtnDDNO.Checked == true) { lblGridTitle.Text = "DD No. " + txtDiary.Text.ToString(); qry = "select IMID,DiaryNo,Session,SubDate as Date,AmtFor,DDDate,DDNO,Bank,Narration,Amt as Amount from FeeAC where DDNO='" + txtDiary.Text.ToString() + "' and Session='" + lblSessionHidden.Text.ToString() + "' order by SubDate Desc"; } SqlDataAdapter ad = new SqlDataAdapter(qry, con); DataTable dt = new DataTable(); ad.Fill(dt); GridAC.DataSource = dt; GridAC.DataBind(); if (GridAC.Rows.Count > 0) { GridAC.Focus(); } else { btnView.Focus(); } } catch (FormatException ex) { GridAC.DataBind(); if (GridAC.Rows.Count > 0) { GridAC.Focus(); } else { btnView.Focus(); } } finally { con.Close(); con.Dispose(); } }
protected void btnVeiw_OnClick(object sender, EventArgs e) { try { SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["Conn"]); string qry = ""; dtinfo.ShortDatePattern = "dd/MM/yyyy"; dtinfo.DateSeparator = "/"; con.Close(); con.Open(); if (rbtnICE.Checked == true) { lblGridTitle.Text = "Date: " + txtDateFrom.Text + " To: " + txtDateto.Text.ToString(); qry = "select IMID,DiaryNo,Session,Date,Amount,Type,Balance,Details from Account where Date Between '" + Convert.ToDateTime(txtDateFrom.Text, dtinfo) + "' and '" + Convert.ToDateTime(txtDateto.Text, dtinfo) + "' ORDER BY SN DESC"; } else if (rbtnIM.Checked == true) { lblGridTitle.Text = "IMID: " + txtIMID.Text.ToString() + " and Session: " + lblSessionHidden.Text.ToString(); qry = "select IMID,DiaryNo,Session,Date,Amount,Type,Balance,Details from Account where Session='" + lblSessionHidden.Text.ToString() + "' and IMID='" + txtIMID.Text.ToString() + "' ORDER BY SN DESC"; } else if (rbtnDiary.Checked == true) { lblGridTitle.Text = "Diary No. " + txtDiary.Text.ToString(); qry = "select IMID,DiaryNo,Session,Date,Amount,Type,Balance,Details from Account where DiaryNo='" + txtDiary.Text.ToString() + "' ORDER BY SN DESC"; } SqlDataAdapter ad = new SqlDataAdapter(qry, con); DataTable dt = new DataTable(); ad.Fill(dt); GridAC.DataSource = dt; GridAC.DataBind(); GridAC.Focus(); } catch (SqlException ex) { } catch (FormatException ex) { } }