如何将我的gridview数据传输到另一个aspx页面?

时间:2019-02-05 12:00:27

标签: c# asp.net

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();


}

如何传输此数据并在另一页的文本框中显示?

1 个答案:

答案 0 :(得分:0)

您可以在会话中使用查询字符串或存储值,并在下一页页面加载时检索该值。

  

username.Value = Request [“ username”];   username.Value =会话[“ username”]。toString();