Dear Sir,
I want to display data as status wise in lable.
staus : Open, closed, Suspended, In progrss.
namespace gridview_filter
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Filter"] = "ALL";
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("spx_GetOCMSip");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Filter", ViewState["Filter"].ToString());
// cmd.Parameters.AddWithValue("@From", !string.IsNullOrEmpty(txtFrom.Text.Trim()) ? txtFrom.Text.Trim() : (object)DBNull.Value);
//cmd.Parameters.AddWithValue("@To", !string.IsNullOrEmpty(txtTo.Text.Trim()) ? txtTo.Text.Trim() : (object)DBNull.Value);
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
DropDownList ddlCountry =
(DropDownList)GridView1.HeaderRow.FindControl("ddlCountry");
this.BindCountryList(ddlCountry);
}
protected void CountryChanged(object sender, EventArgs e)
{
DropDownList ddlCountry = (DropDownList)sender;
ViewState["Filter"] = ddlCountry.SelectedValue;
this.BindGrid();
}
private void BindCountryList(DropDownList ddlCountry)
{
String strConnString = System.Configuration.ConfigurationManager
.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("select distinct STATUS_NAME" + " from complaint_status");
cmd.Connection = con;
con.Open();
ddlCountry.DataSource = cmd.ExecuteReader();
ddlCountry.DataTextField = "STATUS_NAME";
ddlCountry.DataValueField = "STATUS_NAME";
ddlCountry.DataBind();
con.Close();
ddlCountry.Items.FindByValue(ViewState["Filter"].ToString())
.Selected = true;
}
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
protected void Button1_Click(object sender, System.EventArgs e)
{
}
protected void OnPageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void OnDataBound(object sender, EventArgs e)
{
lblTotal.Text = "Total: " + (GridView1.DataSource as DataTable).Rows.Count;
}
}
}
CREATE TABLE [dbo].[comp_box] (
[COMP_ID] INT IDENTITY (1, 1) NOT NULL,
[EMP_ID] NVARCHAR (10) NULL,
[COMP_MESSAGE] NVARCHAR (MAX) NULL,
[Comp_type] VARCHAR (20) NULL,
[STATUS_ID] NVARCHAR (10) DEFAULT ('01') NOT NULL,
[COMP_LODGE_DATE] DATETIME DEFAULT (getdate()) NULL,
[CLOSING_DATE] DATETIME NULL,
[REMARKS] VARCHAR (255) NULL,
[S_GUID] UNIQUEIDENTIFIER NULL,
[remote_ip] NVARCHAR (50) NULL,
[who] NVARCHAR (50) NULL,
[user_feedback] NVARCHAR (255) NULL,
[type] NVARCHAR (255) NULL,
[ATTEND_DATE] DATETIME NULL,
[ATTEND_BY] VARCHAR (255) NULL,
[Image] VARCHAR (50) NULL,
[remote_A_ip] NVARCHAR (50) NULL,
CONSTRAINT [PK_comp_box] PRIMARY KEY CLUSTERED ([COMP_ID] ASC)
);
CREATE PROCEDURE spx_GetOCMSip
@Filter VARCHAR(50)
AS
BEGIN
SET NOCOUNT ON;
IF @Filter = 'ALL'
select a.COMP_ID,a.EMP_ID,a.COMP_MESSAGE,a.STATUS_ID,a.COMP_LODGE_DATE,a.CLOSING_DATE,a.REMARKS,a.ATTEND_DATE,a.ATTEND_BY,b.STATUS_NAME,a.remote_ip,c.EMP_NAME,c.VSAT_PHONE,c.phone_off,c.phone_mob from comp_box a,emp c,complaint_status b where a.emp_id=c.emp_id and a.STATUS_ID=b.STATUS_ID order by a.comp_lodge_date desc
ELSE IF @Filter = '10'
SELECT TOP 10 a.COMP_ID,a.EMP_ID,a.COMP_MESSAGE,a.STATUS_ID,a.COMP_LODGE_DATE,a.CLOSING_DATE,a.REMARKS,a.ATTEND_DATE,a.ATTEND_BY,b.STATUS_NAME,a.remote_ip,c.EMP_NAME,c.VSAT_PHONE,c.phone_off,c.phone_mob from comp_box a,emp c,complaint_status b where a.emp_id=c.emp_id and a.STATUS_ID=b.STATUS_ID order by a.comp_lodge_date desc
ELSE
select a.COMP_ID,a.EMP_ID,a.COMP_MESSAGE,a.STATUS_ID,a.COMP_LODGE_DATE,a.CLOSING_DATE,a.REMARKS,a.ATTEND_DATE,a.ATTEND_BY,b.STATUS_NAME,a.remote_ip,c.EMP_NAME,c.VSAT_PHONE,c.phone_off,c.phone_mob from comp_box a,emp c,complaint_status b where a.emp_id=c.emp_id and a.STATUS_ID=b.STATUS_ID and b.STATUS_NAME=@Filter order by a.comp_lodge_date desc
END