Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
how to send gridview row values to other page and update that record values and return back to gridview page n tier architecture in asp.net with c#
Posted

Check this one: Passing values from datagrid to another page[^]
Hope it helps..
 
Share this answer
 
HI

you can use the following mathod for this

1)previouspage.findcontrol("testdatatable") as datatable;

and you will get all the values

2)You can also use the session variable session["datatable"]

Hope it will help you

best luck

Thanks
 
Share this answer
 
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using BusinessLogicLayer;

public partial class Admin_EditItem : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
   
        {

            if (!IsPostBack)
            {

                    int PID = Convert.ToInt32(Request.QueryString["ID"]);
                    Session["Pid"] = PID;
               
                fillProductInfo();

            }
                   
    }


    protected void btn_add_Click(object sender, EventArgs e)
    {


        productBLL objproductBLL = new productBLL();

        objproductBLL.Product_Id = 0;
        objproductBLL.ProductName = txt_Pname.Text;


        objproductBLL.Category_Id = Convert.ToInt32(ddl_catg.SelectedValue);
        objproductBLL.Sales_Price = Convert.ToSingle(txt_price.Text.Trim());
        objproductBLL.Description = txt_desc.Text;

        if (FileUpload1.HasFile)
        {
            if (CheckExtension(FileUpload1.FileName))
            {
                if (FileUpload1.PostedFile.ContentLength < 1000000000)
                {
                    string Path = Server.MapPath("~/images/");
                    Path = Path + "//" + FileUpload1.FileName;
                    FileUpload1.SaveAs(Path);

                }
                else
                {

                }
            }
        }

        else
        {



        }


        objproductBLL.ProductImage = "~/images/" + FileUpload1.FileName;



        if (objproductBLL.insertupdateproduct() > 0)
        {

            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "PremierStore", "alert('Update  Successful')", true);
        }
        {
            Label1.Text = "Data Has Been entered Successfully!!!!!!";

        }
    }


    private bool CheckExtension(string fileName)
    {
        string extension = Path.GetExtension(fileName);
        switch (extension.ToLower())
        {
            case ".jpg": return true;
            case ".jpeg": return true;
            case ".png": return true;
            case ".gif": return true;
            default: return false;
        }
    }



    private void fillProductInfo()
    {
        productBLL objProductBLL = new productBLL();
        objProductBLL.Product_Id = Convert.ToInt32(Session["Pid"].ToString());
        DataSet ds = new DataSet();
        ds = objProductBLL.SelectProduct();
        if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            txt_Pname.Text = ds.Tables[0].Rows[0]["productName"].ToString();
            txt_desc.Text = ds.Tables[0].Rows[0]["description"].ToString();
            txt_price.Text = ds.Tables[0].Rows[0]["sales_Price"].ToString();
            Image1.ImageUrl = ds.Tables[0].Rows[0]["productImage"].ToString();
            ddl_catg.SelectedIndex = ddl_catg.Items.IndexOf(ddl_catg.Items.FindByValue(ds.Tables[0].Rows[0]["category_Id"].ToString()));
        }
    }
  protected void clear()
    {
        txt_Pname.Text = "";
        txt_price.Text = "";

        txt_desc.Text = "";


          }

    }
 
Share this answer
 
v3
Dear Friend,

Follow the below steps

Step1:
Create Typed dataset first and then create the datatable inside the typed dataset with same gridview structure.

Step2:
store this typed dataset in session in a common class and then add your gridvalue in the created datatable, so after adding your gridview data it will be maintain thru out your page in session. So you can access dataset any where from your application. So ur data will transfer thru xml format, at the performance point of view it will good.
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900