Thursday, May 22, 2014

How to open a Print view from excel;


         




        Response.ClearContent();
        Response.AddHeader("content-disposition", "attachment; filename=GridViewToExcel.xls");
        Response.ContentType = "application/excel";
        StringWriter sWriter = new StringWriter();
        HtmlTextWriter hTextWriter = new HtmlTextWriter(sWriter);
        HtmlForm hForm = new HtmlForm();
        RegionalGrid.Parent.Controls.Add(hForm);
        hForm.Attributes["runat"] = "server";
        hForm.Controls.Add(RegionalGrid);
        hForm.RenderControl(hTextWriter);
        Response.Write(sWriter.ToString());
        Response.End();

Tuesday, May 20, 2014

Filering values in a Dataset

Hi all,
 Today I'm going to tell you about filtering values from a Dataset where the data get from SQl and stored in a dataset.
 Later on you need to filter the values for a given criteria from the dataset you have.
 you can do that by:

 DataSet DSpocode=new DataSet();
 DSpocode="Dataset select from SQL"
 DataTable table = DSpocode.Tables[0];
 for (int i = 0; i < DSpocode.Tables[0].Rows.Count; i++)
 {
 string expression = " substr('PD_CODE',3) like'%" + 65600+ "%'";
 DataRow[] foundRows = table.Select(expression);
 int rowCount = foundRows.Length;
}
 // PD_CODE is the coliumn name in the dataset.
 //I got the count where PD code like 65600. Likewise you can alter this to fulfill your requirement.

Thanks.