i am using master page with form tag runat server
but on my dedicated page to master page, i am using two gridviews to get data by corresponding click from grid1 and get value in grid2.
i am using itextsharp for save file in pdf from grid2.
the problem is when i run the command on browser
it shows error that is gridview2 should be under form tag. that i already given in the master page. how would i get the optimal solution for this.
what i have treied as follows:-
HERE IS MY CS CODE:-
enter code here
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data;
using System.Data.SqlClient;
using iTextSharp.text;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.IO;
using System.Text;
public partial class list : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(WebConfigurationManager.ConnectionStrings["ledgerConnection"].ConnectionString);
SqlCommand cmd = new SqlCommand();
DataSet ds = new DataSet();
SqlDataAdapter sda = new SqlDataAdapter();
protected void Page_Load(object sender, EventArgs e)
{
//userLabel.Text = "" + "" + "" + Session["user"] + "";
userLabel.Text = Session["user"].ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
base.VerifyRenderingInServerForm(control);
}
protected void button1_Click(object sender, EventArgs e)
{
string search = searchtext.Text;
ViewState["searchvals"] = search;
getdata(search);
GridView2.DataSource = null;
GridView2.DataBind();
}
public void getdata(string search)
{
con.Open();
SqlCommand cmd = new SqlCommand("select pk_id, ma_accname from master where ma_accname LIKE '%' + @search + '%' and userId=" + Convert.ToInt32(Session["user"]) + "", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.AddWithValue("@search", search);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (con.State == ConnectionState.Closed)
con.Open();
cmd = new SqlCommand();
cmd.CommandText = "sp_getDataML";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@gl_acid", GridView1.SelectedValue);
cmd.Parameters.AddWithValue("@userid", Convert.ToInt32(Session["user"]));
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridPageIndex1(object sender, GridViewPageEventArgs e)
{
/*Fill Gridview*/
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
{
getdata(ViewState["searchvals"].ToString());
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "view")
{
int id = Convert.ToInt32(e.CommandArgument);
ViewState["id"] = id;
viewdetaildata();
}
}
public void viewdetaildata()
{
if (con.State == ConnectionState.Closed)
con.Open();
cmd = new SqlCommand();
cmd.CommandText = "sp_getDataML";
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@gl_acid", Convert.ToInt32(ViewState["id"]));
cmd.Parameters.AddWithValue("@userid", Convert.ToInt32(Session["user"]));
SqlDataAdapter adp = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView2.DataSource = dt;
GridView2.DataBind();
}
protected void GridView2_PageIndexChanging1(object sender, GridViewPageEventArgs e)
{
GridView2.PageIndex = e.NewPageIndex;
GridView2.DataBind();
}
protected void ExportToPDF(object sender, EventArgs e)
{
exportGridToPdf();
}
private void exportGridToPdf()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-dispostion", "attachment; filename=grid.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView2.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
GridView2.AllowPaging = true;
GridView2.DataBind();
}
}
HERE IS MY MAIN ASPX:-
enter code here
<%@ Page Title="" Language="C#" MasterPageFile="~/logIn/login.master" AutoEventWireup="true" CodeFile="list.aspx.cs" Inherits="list" %>
function PrintGridData() {
var prtGrid = document.getElementById('<%=GridView2.ClientID %>');
prtGrid.border = 0;
var prtwin = window.open('', 'PrintGridViewData', 'left=100,top=100,width=1000,height=1000,tollbar=0,scrollbars=1,status=0,resizable=1');
prtwin.document.write(prtGrid.outerHTML);
prtwin.document.close();
prtwin.focus();
prtwin.print();
prtwin.close();
}
hello, welcome
HERE IS MY MASTER PAGE:-
enter code here
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="login.master.cs" Inherits="logIn_login" %>
Rajeesh MenothPosted Oct 26, 2016, 5:24 AM
Bikesh SrivastavaPosted Oct 26, 2016, 2:11 PM