protected void BindData()
        {
            if (Session["username"] != null || Session["operator_id"] != null)
            {
                username    = Session["username"].ToString();
                catid       = Convert.ToString(Session["category"]);
                operator_id = ddlLco.SelectedValue.Split('#')[0].ToString(); //Convert.ToString(Session["operator_id"]);
            }
            else
            {
                Session.Abandon();
                Response.Redirect("~/Login.aspx");
                return;
            }

            cls_Business_rptLcowiseUserdetails objTran = new cls_Business_rptLcowiseUserdetails();
            DataTable dt = objTran.getLcodetails(username, catid, operator_id);

            if (dt.Rows.Count == 0)
            {
                btnAll.Visible     = false;
                grdLcodet.Visible  = false;
                lblSearchMsg.Text  = "No data found";
                btngrnExel.Visible = false;
            }
            else
            {
                btnAll.Visible            = true;
                btngrnExel.Visible        = true;
                grdLcodet.Visible         = true;
                btngrnExel.Visible        = true;
                lblSearchMsg.Text         = "";
                ViewState["searched_Lco"] = dt;
                grdLcodet.DataSource      = dt;
                grdLcodet.DataBind();
            }
        }
        protected void btn_genExl_Click(object sender, EventArgs e)
        {
            string username, catid, operator_id;

            if (Session["username"] != null || Session["operator_id"] != null)
            {
                username    = Session["username"].ToString();
                catid       = Convert.ToString(Session["category"]);
                operator_id = ddlLco.SelectedValue.Split('#')[0].ToString(); //Convert.ToString(Session["operator_id"]);
            }
            else
            {
                Session.Abandon();
                Response.Redirect("~/Login.aspx");
                return;
            }

            cls_Business_rptLcowiseUserdetails objTran = new cls_Business_rptLcowiseUserdetails();
            DataTable dt = objTran.getLcodetails(username, catid, operator_id);

            if (dt.Rows.Count != 0)
            {
                DateTime dd       = DateTime.Now;
                string   datetime = dd.Day + "" + dd.Month + "" + dd.Year + "" + dd.Hour + "" + dd.Minute + "" + dd.Second;

                StreamWriter sw = new StreamWriter(Server.MapPath("../MyExcelFile/") + "LcoDetails_" + datetime + ".xls");
                try
                {
                    int    j         = 0;
                    String strheader = "Sr.No." + Convert.ToChar(9)
                                       + "LCO Code" + Convert.ToChar(9)
                                       + "LCO Name" + Convert.ToChar(9)
                                       + "Company Name" + Convert.ToChar(9)
                                       + "Distributor" + Convert.ToChar(9)
                                       + "Sub Distributor" + Convert.ToChar(9)
                                       + "State" + Convert.ToChar(9)
                                       + "City" + Convert.ToChar(9)
                                       + "User Count" + Convert.ToChar(9);

                    while (j < dt.Rows.Count)
                    {
                        sw.WriteLine(strheader);

                        for (int i = 0; i < dt.Rows.Count; i++)
                        {
                            j = j + 1;
                            string strrow = j.ToString() + Convert.ToChar(9) + "'"
                                            + dt.Rows[i]["lcocode"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["lconame"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["companyname"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["distributor"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["subdistributor"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["statename"].ToString() + Convert.ToChar(9)
                                            + dt.Rows[i]["cityname"].ToString() + Convert.ToChar(9);
                            strrow += dt.Rows[i]["usercnt"].ToString() + Convert.ToChar(9);
                            sw.WriteLine(strrow);
                        }
                    }
                    sw.Flush();
                    sw.Close();
                }
                catch (Exception ex)
                {
                    sw.Flush();
                    sw.Close();
                    Response.Write("Error : " + ex.Message.Trim());
                    return;
                }
                Response.Redirect("../MyExcelFile/" + "LcoDetails_" + datetime + ".xls");
            }

            if (dt == null)
            {
                Response.Redirect("~/ErrorPage.aspx");
                return;
            }
        }