Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am using gridview with 10 columns and in that I have created one hyperlink for one column i.e. patientID. When i click this hyperlink all the data should be transfer to next webform i.e. to OPD.aspx page. In that OPD.aspx i have textbox and dropdownlist and the selected gridview link data should get transfer to these textbox nad dropdownlist.


From Search.aspx to OPD.aspx


Thanks in advance
Posted
Updated 7-May-21 21:12pm
Comments
Mahesh Bailwal 10-Oct-13 6:39am    
Did you thought of using Asp.Net Session object. Where you can keep value in one page and fetch that in any other page?
Dhanashri_G 10-Oct-13 7:03am    
I had given a thought over it. But I want to select the contents from gridview and after selecting it tha data should be seen in another webpage.
PoojaGahlaut 10-Oct-13 7:18am    
Easiest way of doing it is using session variables. Query string can be used if data is not sensitive. Or try creating an entity class for Patient and create session from object of Patient class.

create a link button in this
C#
<asp:linkbutton id="LinkButton1" runat="server" postbackurl="<%#"~/Guest/Default.aspx?id="+Eval("patientID") %>">Add To Cart</asp:linkbutton>

then on next page you can retrieve this value on label id on page load like this
C#
string id = Request.QueryString["id"];

now pass this id in your query and then retrieve your value in text box and dropdown
 
Share this answer
 
v2
You may use
Query Strings
Cookies
Session variables
Server.Transfer
Post Back URL


Passing data/parameters/values from one aspx page to another aspx page[^]
Passing Values from One Page to Another Page – ASP.NET[^]
 
Share this answer
 
Use Query string,below is some code for this may it help you...

C#
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
           GridViewRow row = GridView1.SelectedRow;
           StringBuilder pageUrl = new StringBuilder();

           pageUrl.Append("Demo.aspx?Survey=");
           pageUrl.Append(row.Cells[1].Text);
           pageUrl.Append("&SubSurvey=");
           pageUrl.Append(row.Cells[2].Text);
           pageUrl.Append("&Name=");
           pageUrl.Append(row.Cells[3].Text);
           pageUrl.Append("&Contact=");
           pageUrl.Append(row.Cells[4].Text);
           pageUrl.Append("&UserID=");
           pageUrl.Append(row.Cells[5].Text);

           Response.Redirect(pageUrl.ToString());
}
 
Share this answer
 
C#
create a link button in gridview
 
<asp:linkbutton id="LinkButton1" runat="server" postbackurl="<%#"~/OPD.aspx?Id="+Eval("patientID") %>">;/asp:linkbutton>
then on OPD page you can retrieve this value of Id on page load like this

string id = Request.QueryString["Id"];

now pass this id in your query and then retrieve your all data from table and fill it in text box and dropdown
 
Share this answer
 
v2
First.aspx.cs
make PostBackUrl="~/Second.aspx"

  if (dataTable.Rows.Count > 0)
                    {
                        for (int i = 1; i <= dataTable.Rows.Count; i++)
                        {
                            dataRow = dataTable.NewRow();
                            dataRow["UID"] = TextBox3.Text;
                            dataRow["Article"] = HiddenField1.Value;
                            dataRow["Description"] = DropDownList1.SelectedValue;
                            dataRow["Qty"] = TextBox5.Text;
                            dataRow["Total"] = TextBox7.Text;
                            dataRow["Quantity"] = TextBox6.Text;
                            dataRow["Order Qty"] = TextBox8.Text;
                            dataRow["Grade"] = TextBox9.Text;
                            dataRow["Model"] = TextBox10.Text;
                            dataRow["OD"] = TextBox11.Text;
                            dataRow["Length"] = TextBox12.Text;
                            dataRow["ID"] = TextBox13.Text;
                        }
                        if (dataTable.Rows[0][0].ToString() == "")
                        {
                            dataTable.Rows[0].Delete();
                            dataTable.AcceptChanges();
                        }
                        ViewState["order"] = dataTable;
                        GridView1.DataSource = dataTable;
                        dataTable.Rows.Add(dataRow);
                        GridView1.DataBind();

                        Session["order"] = dataTable;

Second.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                System.Data.DataTable dt = (System.Data.DataTable)Session["order"];
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

        }
 
Share this answer
 
v2
Comments
Richard Deeming 20-Feb-19 9:51am    
Adds nothing that hasn't already been covered in the four accepted solutions.
Sir,
Instead of transferring to Second page, is it possible to get displayed in the "same page" just below the gridView, so that I dont let the user to switch between pages.
Please help with a sample code.
Thanks
 
Share this answer
 
Comments
CHill60 10-May-21 4:51am    
If you want to ask a question, then use the red "Ask a Question" link at the top of this page. Do not post comments or questions as a Solution to another member's post

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