DataTable dt = new DataTable();
string str1;
str1 = "SELECT Testt1.StudentCode, Student.StudentID,Student.Name, Testt1.FMark,'' as 'LMark','' as'Status',''as 'Promote' FROM Testt1 INNER JOIN School ON Testt1.SchoolCode = School.SchoolCode INNER JOIN Student ON Testt1.StudentCode = Student.StudentCode where Testt1.Promote ='Yes' and School.SchoolCode =" + DropDownList3.SelectedValue + "";
dt = ObjConn.GetDataTable(str1);
HttpResponse response = HttpContext.Current.Response;
response.Clear();
//response.Charset = "";
response.ContentType = "application/vnd.ms-excel";
response.AddHeader("Content-Disposition", "attachment;filename=Smarks.xls");
//response.AddHeader("Content-Disposition", "C:\"" + fileName + "\"");
StringWriter sw = new StringWriter();
HtmlTextWriter htw = new HtmlTextWriter(sw);
DataGrid dg = new DataGrid();
dg.DataSource = dt;
dg.DataBind();
dg.RenderControl(htw);
response.Write(sw.ToString());
response.End();