简体   繁体   中英

How can i transfer my gridview data to another aspx page?

Inward.aspx

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="pono" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
        <Columns>
            <asp:CommandField SelectText="Update" ShowSelectButton="True" />
            <asp:BoundField DataField="pono" HeaderText="pono" ReadOnly="True" SortExpression="pono" />
            <asp:BoundField DataField="podate" HeaderText="podate" SortExpression="podate" />
            <asp:BoundField DataField="partyname" HeaderText="partyname" SortExpression="partyname" />
            <asp:BoundField DataField="flag" HeaderText="flag" SortExpression="flag" />
            <asp:BoundField DataField="itemnm" HeaderText="itemnm" SortExpression="itemnm" />
            <asp:BoundField DataField="indt" HeaderText="indt" SortExpression="indt" />
            <asp:BoundField DataField="qty" HeaderText="qty" SortExpression="qty" />
        </Columns>
    </asp:GridView>

inward.aspx.cs

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    string pono = GridView1.SelectedRow.Cells[0].Text;
    Response.Redirect("Update_inward.aspx?pono="+pono);
}

update_inward.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    string stcon = ConfigurationManager.ConnectionStrings["testConnectionString"].ConnectionString;
    SqlConnection con = new SqlConnection(stcon);
    con.Open();
    String query = "Select * from maxus_in where pono=" + Request.QueryString["pono"];
    SqlCommand cmd = new SqlCommand(query, con);
    SqlDataAdapter sda = new SqlDataAdapter(cmd);
    DataSet ds = new DataSet();
    sda.Fill(ds);
    if (ds.Tables[0].Rows.Count > 0)
    {
        TextBox1.Text = ds.Tables[0].Rows[0]["pono"].ToString();
        TextBox2.Text = ds.Tables[0].Rows[0]["podate"].ToString();
        TextBox3.Text = ds.Tables[0].Rows[0]["partyname"].ToString();
        TextBox4.Text = ds.Tables[0].Rows[0]["itemnm"].ToString();
    }
    con.Close();


}

How do i transfer this data and display in textboxes in another page??

You can Use Query String or store value in the session and retrieve the value on page load of the next page.

username.Value = Request["username"]; username.Value = Session["username"].toString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM