I've doubt about report page coding

Posted by Sudheep.grandhe under C# on 10/14/2011 | Points: 10 | Views : 1371 | Status : [Member] | Replies : 4
Hi,

In my project having report page and it contains the gridview.in the button click event he declared the code as griddata();and agian he calling public griddata() like this.is it correct?.i want to declare this type of coding.how can i.please do the needful.

Best,
Sudheep.



Responses

Posted by: Gausi on: 10/14/2011 [Member] Starter | Points: 25

Up
0
Down
hi Sudheep,

please provide your sample code for better understanding of question.

Regards,

Gaurav Singh
(gausi)

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 10/14/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

using System;
using System.Text;
using System.Collections.Specialized;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Collections.Generic;
using System.Globalization;
namespace ImageServices
{
public partial class WebForm18 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
fillddlbox();
//Label1.Text = "";
//Label2.Text = "";
//Label3.Text = "";
//Label4.Text = "";


}

}
public void fillddlbox()
{
SqlConnection con = new SqlConnection("Data Source=marsweb-104;Initial Catalog=ImageServices;Integrated Security=True");
SqlCommand cmd = new SqlCommand("select CustId,CustName from tbl_Customer ORDER BY CustName", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ddl_CustName.DataSource = dt;
ddl_CustName.DataValueField = "CustId";
ddl_CustName.DataTextField = "CustName";
ddl_CustName.DataBind();

}
ddl_CustName.Items.Insert(0,"Select One");



}

protected void btn_Submit_Click(object sender, EventArgs e)
{
griddata();
}
public void griddata()
{

string strInvoiceStartDate, strInvoiceStartDate1, InvoiceStartDate, strInvoiceEndDate, strInvoiceEndDate1, InvoiceEndDate;
SqlConnection con1 = new SqlConnection("Data Source=marsweb-104;Initial Catalog=ImageServices;Integrated Security=True");
SqlCommand cmd1 = new SqlCommand("Select CompName,CompAddress,InvoiceNo,OrderNo,OnDate,InvoiceDate,AmountStatus,NetAmount,NetVat,TAmount from tbl_Report2 WHERE CompName=@CustName AND AmountStatus=@AmountStatus AND InvoiceDate BETWEEN @StartDate AND @EndDate", con1);


cmd1.Parameters.AddWithValue("@CustName",ddl_CustName.SelectedItem.Text.ToString());

strInvoiceStartDate = txt_StartDate.Text;
if (strInvoiceStartDate != "Null")
{
char[] seperator = new char[] { ' ' };
string[] s1 = strInvoiceStartDate.Split(seperator);
string date2 = s1[0].ToString();

if (date2 != "Null")
{
char[] seperator1 = new char[] { '-' };
string[] s2 = date2.Split(seperator1);
string day = s2[0].ToString();
string month = s2[1].ToString();
string year = s2[2].ToString();
strInvoiceStartDate1 = (year + "-" + month + "-" + day);
InvoiceStartDate = strInvoiceStartDate1 + " " + "00:00:00.000";
cmd1.Parameters.AddWithValue("@StartDate", InvoiceStartDate);


}

}
strInvoiceEndDate = txt_EndDate.Text;
if (strInvoiceEndDate != "Null")
{
char[] seperator = new char[] { ' ' };
string[] s1 = strInvoiceEndDate.Split(seperator);
string date2 = s1[0].ToString();

if (date2 != "Null")
{
char[] seperator1 = new char[] { '-' };
string[] s2 = date2.Split(seperator1);
string day = s2[0].ToString();
string month = s2[1].ToString();
string year = s2[2].ToString();
strInvoiceEndDate1 = (year + "-" + month + "-" + day);
InvoiceEndDate = strInvoiceEndDate1 + " " + "00:00:00.000";
cmd1.Parameters.AddWithValue("@EndDate", InvoiceEndDate);


}

}

cmd1.Parameters.AddWithValue("@AmountStatus",rbl_Status.SelectedItem.Text.ToString());
SqlDataAdapter da = new SqlDataAdapter(cmd1);
DataTable dt = new DataTable();
da.Fill(dt);
Session["alldata"] = dt;
if (dt.Rows.Count > 0)
{
lbl_Message.Text = "";
GridView1.DataSource = dt;
GridView1.DataBind();

}
else
{
GridView1.Controls.Clear();
lbl_Message.Text = "Data Not Found";
}


}



Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jiji on: 10/14/2011 [Member] Starter | Points: 25

Up
0
Down
u just call Public void griddata() whereever u want.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Gausi on: 10/14/2011 [Member] Starter | Points: 25

Up
0
Down
hi Sudheep,

there is nothing wrong in your code ,
in fact for code re-usability u can create a method and use whereever u want.

Regards,

Gaurav Singh
(gausi)

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response