Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Data not transfering to another page

Data not transfering to another page

Scheduled Pinned Locked Moved ASP.NET
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    developerit
    wrote on last edited by
    #1

    iam taking data from one page gridview to another page in session but it is not displaying in another page gridview please check my code and give suggestion which helps me string constr = "Data Source=MAINSERVER;Initial Catalog=Inventory;User ID=sa;Password=nsg_ss_0103"; protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { GridView1.PageIndex = 0; bindata(); } } private void bindata() { SqlConnection con12 = new SqlConnection(constr); SqlDataAdapter da12 = new SqlDataAdapter("SELECT [CategoryNameE], [ItemKey], [ItemKeyNameE], [CurrentQTY], [SalesPrice] FROM [CurrentInWH]", con12); DataSet ds = new DataSet(); da12.Fill(ds, "t"); GridView1.DataSource = ds.Tables["t"]; GridView1.DataBind(); } private void GetGridViewData() { DataTable dt; if(Session["CheckedRecords"]!=null) //if (ViewState["CheckedRecords"] != null) dt = (DataTable)Session["CheckedRecords"]; else dt = CreateNewTable(); for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chk"); if (chk.Checked) { dt = AddNewRow(GridView1.Rows[i], dt); } else { dt = RemoveRow(GridView1.Rows[i], dt); } } Session["CheckedRecords"] = dt; } private DataTable CreateNewTable() { DataTable dt = new DataTable(); dt.Columns.Add("CategoryNameE"); dt.Columns.Add("ItemKey"); dt.Columns.Add("ItemKeyNameE"); dt.Columns.Add("CurrentQTY"); dt.Columns.Add("SalesPrice"); dt.Columns.Add("Quantity"); dt.Columns.Add("Total"); dt.AcceptChanges(); return dt; } private DataTable AddNewRow(GridViewRow gvrow, DataTable dt) { DataRow[] dr = dt.Select("ItemKey = '" + gvrow.Cells[2].Text + "'"); if (dr.Length <= 0) { dt.Rows.Add(); dt.Rows[dt.Rows.Count - 1]["CategoryNameE"] = gvrow.Cells[1].Text; dt.Rows[dt.Rows.Count - 1]["ItemKey"] = gvrow.Cells[2].Text; dt.Rows[dt.Rows.Count - 1]["ItemKeyNameE"] = gvrow.Cells[3].Text; dt.Rows[dt.Rows.Count - 1]["CurrentQTY"] = gvrow.Cell

    D T 2 Replies Last reply
    0
    • D developerit

      iam taking data from one page gridview to another page in session but it is not displaying in another page gridview please check my code and give suggestion which helps me string constr = "Data Source=MAINSERVER;Initial Catalog=Inventory;User ID=sa;Password=nsg_ss_0103"; protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { GridView1.PageIndex = 0; bindata(); } } private void bindata() { SqlConnection con12 = new SqlConnection(constr); SqlDataAdapter da12 = new SqlDataAdapter("SELECT [CategoryNameE], [ItemKey], [ItemKeyNameE], [CurrentQTY], [SalesPrice] FROM [CurrentInWH]", con12); DataSet ds = new DataSet(); da12.Fill(ds, "t"); GridView1.DataSource = ds.Tables["t"]; GridView1.DataBind(); } private void GetGridViewData() { DataTable dt; if(Session["CheckedRecords"]!=null) //if (ViewState["CheckedRecords"] != null) dt = (DataTable)Session["CheckedRecords"]; else dt = CreateNewTable(); for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chk"); if (chk.Checked) { dt = AddNewRow(GridView1.Rows[i], dt); } else { dt = RemoveRow(GridView1.Rows[i], dt); } } Session["CheckedRecords"] = dt; } private DataTable CreateNewTable() { DataTable dt = new DataTable(); dt.Columns.Add("CategoryNameE"); dt.Columns.Add("ItemKey"); dt.Columns.Add("ItemKeyNameE"); dt.Columns.Add("CurrentQTY"); dt.Columns.Add("SalesPrice"); dt.Columns.Add("Quantity"); dt.Columns.Add("Total"); dt.AcceptChanges(); return dt; } private DataTable AddNewRow(GridViewRow gvrow, DataTable dt) { DataRow[] dr = dt.Select("ItemKey = '" + gvrow.Cells[2].Text + "'"); if (dr.Length <= 0) { dt.Rows.Add(); dt.Rows[dt.Rows.Count - 1]["CategoryNameE"] = gvrow.Cells[1].Text; dt.Rows[dt.Rows.Count - 1]["ItemKey"] = gvrow.Cells[2].Text; dt.Rows[dt.Rows.Count - 1]["ItemKeyNameE"] = gvrow.Cells[3].Text; dt.Rows[dt.Rows.Count - 1]["CurrentQTY"] = gvrow.Cell

      D Offline
      D Offline
      Dinesh Mani
      wrote on last edited by
      #2

      First and foremost, edit your post and remove the connection details. Its not so good to post your SQL server's sa password on forums even if it is CodeProject. First step to solving this would be to step through your code and identify if the dt that your are persisting in the session has any values. Debug the application, put a break point on the statement Session["CheckedRecords"] = dt;. Check if it has any values before going into the session. If it has values then on the 2nd page check what you are getting out of the session. Again put a break point on the line DataTable dt = (DataTable)Session["CheckedRecords"]; and check the values in dt. Some suggestions [read free advice :-D] 1. Data table is an reference type. You need not return it from AddNewRow and RemoveRow methods. The dt in the calling function and the dt local to AddNewRow and RemoveRow methods point to the same datatable in the heap. Doing this way would just increase the over head on the GC and reduce maintainability of your code. 2. In the AddNewRow method, rather than doing "dt.Rows.Count - 1" every time, do it once and store it as rowNum and use it subsequently. This reduces the number of execution cycles. 3. Format your code. Proper indentation improves readability. HTH!

      1 Reply Last reply
      0
      • D developerit

        iam taking data from one page gridview to another page in session but it is not displaying in another page gridview please check my code and give suggestion which helps me string constr = "Data Source=MAINSERVER;Initial Catalog=Inventory;User ID=sa;Password=nsg_ss_0103"; protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { GridView1.PageIndex = 0; bindata(); } } private void bindata() { SqlConnection con12 = new SqlConnection(constr); SqlDataAdapter da12 = new SqlDataAdapter("SELECT [CategoryNameE], [ItemKey], [ItemKeyNameE], [CurrentQTY], [SalesPrice] FROM [CurrentInWH]", con12); DataSet ds = new DataSet(); da12.Fill(ds, "t"); GridView1.DataSource = ds.Tables["t"]; GridView1.DataBind(); } private void GetGridViewData() { DataTable dt; if(Session["CheckedRecords"]!=null) //if (ViewState["CheckedRecords"] != null) dt = (DataTable)Session["CheckedRecords"]; else dt = CreateNewTable(); for (int i = 0; i < GridView1.Rows.Count; i++) { CheckBox chk = (CheckBox)GridView1.Rows[i].Cells[0].FindControl("chk"); if (chk.Checked) { dt = AddNewRow(GridView1.Rows[i], dt); } else { dt = RemoveRow(GridView1.Rows[i], dt); } } Session["CheckedRecords"] = dt; } private DataTable CreateNewTable() { DataTable dt = new DataTable(); dt.Columns.Add("CategoryNameE"); dt.Columns.Add("ItemKey"); dt.Columns.Add("ItemKeyNameE"); dt.Columns.Add("CurrentQTY"); dt.Columns.Add("SalesPrice"); dt.Columns.Add("Quantity"); dt.Columns.Add("Total"); dt.AcceptChanges(); return dt; } private DataTable AddNewRow(GridViewRow gvrow, DataTable dt) { DataRow[] dr = dt.Select("ItemKey = '" + gvrow.Cells[2].Text + "'"); if (dr.Length <= 0) { dt.Rows.Add(); dt.Rows[dt.Rows.Count - 1]["CategoryNameE"] = gvrow.Cells[1].Text; dt.Rows[dt.Rows.Count - 1]["ItemKey"] = gvrow.Cells[2].Text; dt.Rows[dt.Rows.Count - 1]["ItemKeyNameE"] = gvrow.Cells[3].Text; dt.Rows[dt.Rows.Count - 1]["CurrentQTY"] = gvrow.Cell

        T Offline
        T Offline
        Tej Aj
        wrote on last edited by
        #3

        check the reply for your post on: http://opexsolution.com/forum/viewtopic.php?f=15&t=27

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups