private void BindGrid() { ExcelFormatDAL obj = new ExcelFormatDAL(); var lstGridData = obj.SelectForSearch(); if (lstGridData != null && lstGridData.Count > 0) { grdMain.DataSource = lstGridData; grdMain.DataBind(); int startRowOnPage = (grdMain.PageIndex * grdMain.PageSize) + 1; int lastRowOnPage = startRowOnPage + grdMain.Rows.Count - 1; lblcontant.Text = "Showing " + startRowOnPage.ToString() + " - " + lastRowOnPage.ToString() + " of " + lstGridData.Count.ToString(); lblcontant.Visible = true; divpaging.Visible = true; } else { grdMain.DataSource = null; grdMain.DataBind(); lblcontant.Visible = false; divpaging.Visible = false; } }
protected void grdMain_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "GetExcel") { String msg = ""; Int32 RowId = Convert.ToInt32(e.CommandArgument); GridViewRow CurRow = (GridViewRow)grdMain.Rows[RowId]; HiddenField hidLocId = (HiddenField)CurRow.FindControl("hidexcelid"); ExcelFormatDAL obj = new ExcelFormatDAL(); var lst = obj.GetExcel(Convert.ToInt64(hidLocId.Value)); string ExcelName = (Convert.ToString(DataBinder.Eval(lst[0], "Exl_Name")) + ".xlsx"); if (lst != null && lst.Count > 0) { if (ExcelName != "") { if ((System.IO.Path.GetExtension(ExcelName) == ".xlsx")) { Response.ContentType = "Application/xlsx"; Response.AppendHeader("Content-Disposition", "attachment; filename=" + ExcelName); Response.TransmitFile(Server.MapPath("~/ExcelFormat/" + ExcelName)); Response.End(); } else { msg = "Please Check File Extension only (.xlsx) File!"; ShowMessageErr(msg); } } else { strMsg = "File Not Found."; } } } ScriptManager.RegisterStartupScript(this, this.GetType(), "alertstrMsg", "PassMessage('" + strMsg + "')", true); }