private void BindData() { PagedDataSource dt = new PagedDataSource(); BLL.News currentnews = new BLL.News(); currentnews.LoadAll(); currentnews.DefaultView.Sort = "CreatedDate desc"; dt.DataSource = currentnews.DefaultView; dt.AllowPaging = true; dt.PageSize = 10; dt.CurrentPageIndex = PageIndex; uiRepeaterCurrentNews.DataSource = dt; uiRepeaterCurrentNews.DataBind(); uiLinkButtonPrev.Enabled = !dt.IsFirstPage; uiLinkButtonNext.Enabled = !dt.IsLastPage; uiLabelPages.Text = "Page " + (PageIndex + 1).ToString() + " of " + dt.PageCount.ToString() + " Pages"; }
private void BindExportData() { BLL.News objData = new BLL.News(); objData.LoadAll(); uiGridViewExport.DataSource = objData.DefaultView; uiGridViewExport.DataBind(); }
protected void uiLinkButtonExport_Click(object sender, EventArgs e) { string filter = ""; //DataTable dt = new DataTable(); BLL.News news = new BLL.News(); foreach (GridViewRow row in uiGridViewExport.Rows) { System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)row.FindControl("uiCheckBoxExport"); if (cb.Checked) { if (!string.IsNullOrEmpty(filter)) filter += ","; HiddenField hf = (HiddenField)row.FindControl("uiHiddenFieldID"); filter += hf.Value; } } news.LoadAll(); news.Filter = "NewsID in (" + filter + ")"; if (news.RowCount > 0) { StringBuilder sbDocBody = new StringBuilder(); object oMissing = System.Reflection.Missing.Value; /*Application oWordApp = new Application(); Document document = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing); document.Activate();*/ int i = 0; sbDocBody.Append("<html><body>"); foreach (DataRowView item in news.DefaultView) { /*oWordApp.Selection.TypeText(item["EnTitle"].ToString()); oWordApp.Selection.TypeParagraph(); oWordApp.Selection.TypeParagraph(); oWordApp.Selection.InlineShapes.AddPicture("http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString()); oWordApp.Selection.TypeParagraph(); oWordApp.Selection.TypeText(StripTagsCharArray(Server.HtmlDecode(item["EnBody"].ToString()))); oWordApp.Selection.InsertNewPage();*/ sbDocBody.Append(item["EnTitle"].ToString()); sbDocBody.Append("<br />"); sbDocBody.Append("<img src=\'http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString() + "\'"); sbDocBody.Append("<br />"); sbDocBody.Append(Server.HtmlDecode(item["EnBody"].ToString())); sbDocBody.Append("<br />"); sbDocBody.Append("<br />"); sbDocBody.Append("<hr />"); i++; } sbDocBody.Append("</body></html>"); /*document.SaveAs(Server.MapPath("~/fileuploads/News.docx"), oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing); document.Close();*/ HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Buffer = true; HttpContext.Current.Response.Charset = "utf-8"; HttpContext.Current.Response.ContentType = "application/msword"; HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"news.doc\""); //HttpContext.Current.Response.TransmitFile("/fileuploads/News.docx"); HttpContext.Current.Response.Write(sbDocBody.ToString()); //HttpContext.Current.Response.Flush(); HttpContext.Current.Response.End(); //oWordApp.Application.Quit(ref oMissing, ref oMissing, ref oMissing); } else { } }