Transfer data from page to another page

I have a .aspx page (we'll call it Form1) with a
datagrid on it. The datagrid is populated from a dataset
that I manually entered data into (the data isn't in a
database). The datagrid on Form1 has a checkbox.

when i click checkbox the row is selected so the selected row should be displayed in the form2 page.in a grid.when i check the grid it should go back to the grid in the parent page

 

I have another .aspx page (Form2) with an
unpopulated datagrid on it. I want to populate it with
all the columns from the select click of the checkbox row . I just don't know how to pass the row from
aspx page  to another page 

 

can anyone provide me with the code ??

0
renjithgk
5/10/2008 3:58:26 PM
📁 asp.net.getting-started
📃 91979 articles.
⭐ 2 followers.

💬 6 Replies
👁️‍🗨️ 569 Views

Brief code snippet that should do the trick for you, this is only a template for you to work on:

DataTable dt = new DataTable; //create datatable to store your row
DataRow dr = dt.NewRow();   
dr["ColumnName"] = "some data"; //set data to the row
Session["DT"] = dt;

//Retrieve data in another page through Session

DataTable dt = (DataTable)Session["DT"];

 Let me know if you need to know more. 

Thanks

Abhishek

 

0
Abhishek
5/10/2008 5:59:43 PM

 different ways to transfer data frm one page to another page.

1) response.redirect

2) server.transfer

3) server.execute

4) cookies

5) session

http://geekswithblogs.net/ranganh/archive/2005/04/25/37631.aspx

http://www.daniweb.com/forums/thread82311.html 

http://aspnet.4guysfromrolla.com/articles/050802-1.2.aspx 

http://www.ondotnet.com/pub/a/dotnet/2003/04/07/aspnetnav.html 

http://www.codeproject.com/KB/aspnet/TransferingValues.aspx

 check these links

 

0
snovice
5/10/2008 7:14:51 PM

 

Hi Abhishek , Thanks.i would like to know more .can i get more code.in my grid,i have a checkbox when i click the checkbox the row is selected i need to transfer the selected row to another page into a grid.in my second page i am retrieving all values into a grid where checkbox is checked and unchecked.i need the code.pls pls hel pme.

 

Thanks,

Renjith

0
renjithgk
5/11/2008 4:58:36 AM

use Item command event to grid to implement above functionality 


If this post helps you, please mark it as Answer.



Cheers,
Muhammad Rizwan Javed
Sr .Net Developer
Aim 168, Dubai, UAE.
0
Rizwan328
5/11/2008 6:41:39 AM

Hi

I have refined this a lot more for you but please try to understand the logic before implementation. Use this as your template & you should be good.

DataTable dt = new DataTable; //create datatable to store your row

foreach (DataGridItem item in dgr.Items)
    {
                CheckBox chk = (CheckBox)item.FindControl("chk");
                if (chk.Checked == true)
                {
                  TextBox txt = (TextBox)item.FindControl("txt");
                   DataRow dr = dt.NewRow();   
                   dr["ColumnName"] = txt.Text; //set data to the row
                   dt.Rows.Add(dr);
                }
    }

Session["DT"] = dt; //store datatable in session


//Retrieve data in another page through Session

DataTable dt = (DataTable)Session["DT"];
dgr1.DataSource = dt;
dgr1.DataBind();

Please mark post as answer if you think it answered your query. 

Thanks

Abhi

0
Abhishek
5/11/2008 7:03:15 AM

Hi,

Pass value between child page and parent page you can use JavaScript to achieve it.

There are two pages exist. One is main page another is popup page, which must be popuped by main page.

Main page:

    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    </form>

 
        private void Page_Load(object sender, EventArgs e)
        {
            //create our update function
            StringBuilder str = new StringBuilder();
            str.Append("<script language=javascript>");
            str.Append("function update(e){");

            str.Append("document.getElementById('"+TextBox1.ClientID+"').value=e[0];");
            str.Append("document.getElementById('"+TextBox2.ClientID+"').value=e[1];}");
            str.Append("</script>");

            // register the javascript into the Page
            if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "update"))
            {
                Page.RegisterClientScriptBlock("update", str.ToString());
            } 
            Button1.Attributes.Add("onclick", "window.open('Popup.aspx',null,'left=400, top=100, height=250, width= 250, status=no, resizable= no, scrollbars= no, toolbar= no,location= no, menubar= no');");

        }
 

  Popup.aspx:

    <form id="form1" runat="server">
    <div>
        <input id="Text1" type="text" /><input id="Text2" type="text" />
        <asp:Button ID="Button1" runat="server" Text="Button"  />
    </div>
    </form>
 
    private void Page_Load(object sender, System.EventArgs e)
    {

        string str = @"<script language=javascript>
        function Tovalue()
            {  
            var text1=document.getElementById('Text1').value;
            var text2=document.getElementById('Text2').value;
            var ar= new Array(text1,text2);
            window.opener.update(ar);        
            window.close(); 
            }  
           </script>";

            if (!ClientScript.IsClientScriptBlockRegistered(this.GetType(), "Tovalue"))
            {
                 ClientScript.RegisterClientScriptBlock(this.GetType(), "Tovalue", str.ToString());
            }      

            Button1.Attributes.Add("onclick", "Tovalue();");
    }
 

In the codes above, you can use Array in JavaScript to achieve multiple values being transfered.

The above code can achieve comunicating between child page and parent page. You can modify a part of codes to achieve your purpose.

In your case, you can fire to transfer the value to another page via JavaScript when checkbox is checked.

Hope it helps.

 



Vince Xu
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
0
Vince
5/13/2008 8:59:05 AM
Reply: