but when I select a value from the dropdownlist, my datagrid disappears.
protected override void OnInit(EventArgs e)
{
if (!IsPostBack)
{
Page.DataBind();
ViewState["Filter"] = "ALL";
BindGrid();
}
}
private void BindGrid()
{
DataTable dt = new DataTable();
String strConnString = "Server = 192.168.200.81\\NEW_VANTAGE; Database = MSD; User ID = sa; Password =
[email protected]";
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("spx_GetCustomers");
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@Filter", ViewState["Filter"].ToString());
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
DropDownList ddlCustomer =
(DropDownList)GridView1.HeaderRow.FindControl("ddlCustomer");
this.BindCustomerList(ddlCustomer);
}
private void BindCustomerList(DropDownList ddlCustomer)
{
String strConnString = "Server = 192.168.200.81\\NEW_VANTAGE; Database = MSD; User ID = sa; Password =
[email protected]";
SqlConnection con = new SqlConnection(strConnString);
SqlDataAdapter sda = new SqlDataAdapter();
SqlCommand cmd = new SqlCommand("select distinct CustomerName" +
" from ActiveIssue where type= 'AV Defender Status' group by CustomerName");
cmd.Connection = con;
con.Open();
ddlCustomer.DataSource = cmd.ExecuteReader();
ddlCustomer.DataTextField = "CustomerName";
ddlCustomer.DataValueField = "CustomerName";
ddlCustomer.DataBind();
con.Close();
ddlCustomer.Items.FindByValue(ViewState["Filter"].ToString())
.Selected = true;
}
protected void CustomerChanged(object sender, EventArgs e)
{
DropDownList ddlCustomer= (DropDownList)sender;
ViewState["Filter"] = ddlCustomer.SelectedValue;
GridView1.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ViewState["Filter"] = "ALL";
BindGrid();
}
}
protected void OnPaging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.BindGrid();
}
}
}