Example #1
0
    private void oThertext()
    {
        SqlConnection cono = new SqlConnection(constr);

        cono.Open();

        try
        {
            string     str = "select AMS_AssetID,AMS_AssetName,AMS_AssetType,AMS_Company_Location,AMS_Date_of_Purchase,AMS_Remarks from Asset_Master where (AMS_AssetID Like '%' + @AMS_AssetID +'%' or " + "AMS_AssetName Like '%' + @AMS_AssetName + '%'  or " + " AMS_AssetType = @AMS_AssetType or " + " AMS_Company_Location Like '%' + @AMS_Company_Location )";
            SqlCommand cmd = new SqlCommand(str, cono);
            cmd.Parameters.Add("@AMS_AssetID", SqlDbType.NVarChar).Value          = txtFindVendor.Text;
            cmd.Parameters.Add("@AMS_AssetName", SqlDbType.NVarChar).Value        = txtFindVendor.Text;
            cmd.Parameters.Add("@AMS_AssetType", SqlDbType.NVarChar).Value        = ReportAssetType.SelectedValue.Trim();
            cmd.Parameters.Add("@AMS_Company_Location", SqlDbType.NVarChar).Value = txtFindVendor.Text.Trim();
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = cmd;
            DataSet ds = new DataSet();
            da.Fill(ds, "@AMS_AssetID");
            da.Fill(ds, "@AMS_AssetName");
            da.Fill(ds, "@AMS_AssetType");
            da.Fill(ds, "@AMS_Company_Location");

            Othersgridview.DataSource = ds;
            Othersgridview.DataBind();
        }
        catch (Exception)
        {
            ClientScript.RegisterStartupScript(GetType(), "alert", "alert('There is no approved Data.');", true);
        }
        finally
        {
            cono.Close();
        }
    }
Example #2
0
    private void Othergrid()
    {
        //try
        //{
        Response.Clear();
        Response.Buffer = true;
        Response.AddHeader("content-disposition", "attachment;filename=ExportGridData.xls");
        Response.Charset     = "";
        Response.ContentType = "application/vnd.ms-excel";

        using (System.IO.StringWriter StringWriter = new System.IO.StringWriter())
        {
            HtmlTextWriter HtmlTextWriter = new HtmlTextWriter(StringWriter);


            Othersgridview.AllowPaging = false;

            this.oThertext();

            Othersgridview.CssClass = "rounded_corners";
            foreach (GridViewRow row in Othersgridview.Rows)
            {
                foreach (TableCell cell in row.Cells)
                {
                    cell.Attributes.CssStyle["text-align"] = "center";
                    List <Control> controls = new List <Control>();
                    //Add controls to be removed to Generic List
                    foreach (Control control in cell.Controls)
                    {
                        controls.Add(control);
                    }
                    //Loop through the controls to be removed and replace then with Literal
                    foreach (Control control in controls)
                    {
                        switch (control.GetType().Name)
                        {
                        case "Label":
                            cell.Controls.Add(new Literal {
                                Text = (control as Label).Text
                            });
                            break;
                        }
                        cell.Controls.Remove(control);
                    }
                }
            }
            Othersgridview.RenderControl(HtmlTextWriter);
            Response.Write(StringWriter.ToString());
            Response.End();
        }
        //}
        //catch (Exception ex)
        //{
        //   throw ex;
        //}
    }
Example #3
0
 protected void txtFindVendor_TextChanged(object sender, EventArgs e)
 {
     if (Page.IsPostBack == true)
     {
         searchdiv.Visible = true;
         if (txtFindVendor.Text != string.Empty.ToString() && ReportAssetType.SelectedIndex == 1)
         {
             Othersgridview.DataSourceID = "SWSqlDataSource";
             Othersgridview.DataBind();
             if (Othersgridview.Rows.Count == 0)
             {
                 txtFindVendor.Text           = string.Empty;
                 Othersgridview.Visible       = true;
                 Othersgridview.EmptyDataText = "No Records Found / Invalid Search";
                 Otherexporttoexcell.Visible  = false;
             }
             else
             {
                 Otherexporttoexcell.Visible = true;
             }
         }
         else if (txtFindVendor.Text != string.Empty.ToString() && ReportAssetType.SelectedIndex == 2)
         {
             Othersgridview.DataSourceID = "HWSqlDataSource";
             Othersgridview.DataBind();
             if (Othersgridview.Rows.Count == 0)
             {
                 txtFindVendor.Text           = string.Empty;
                 Othersgridview.Visible       = true;
                 Othersgridview.EmptyDataText = "No Records Found / Invalid Search";
                 Otherexporttoexcell.Visible  = false;
             }
             else
             {
                 Otherexporttoexcell.Visible = true;
             }
         }
         else
         {
             Response.Redirect("~/Admin/Asset-Reports.aspx");
         }
     }
 }