How to pass information between web forms in asp.net

后端 未结 5 1099
面向向阳花
面向向阳花 2021-01-02 14:18

how to send some information from one web form to another web form in asp.net first web form is HumanList.aspx that shows the list of humans in a GridView

5条回答
  •  南方客
    南方客 (楼主)
    2021-01-02 14:50

    Say You have a gridview1 with a button field Say "Modify" First Provide a command Name to that field Say "Mod" Now in Gridview1_RowCommand() function of HumanList.aspx page write the code like this-

    switch (e.CommandName.Trim())
    {
    case "Mod":
    int r1=Int32.Parse((e.CommandArgument).ToString());
    Session["id"]=GridView1.DataKeys[r1].Value.ToString();
    Response.Redirect("HumanEdit.aspx?id=" + Session["id"]);
    break;
    }
    

    Now in HumanEdit.aspx.cs you can make your own class and with in that class you can have a datatable object.Store the Sql query in that object and call that class in page_load(). Say class is

    Public void show()
    {
    Within datatable object you can write your query like this
    select x,y,z, from tbl_name where id=" + Request.QueryString["id"]
    if(dt.Rows.Count>0)
    {
    Xtext.Text=dt.Rows[0]["x"].ToString();
    Ytext.Text=dt.Rows[0]["y"].ToString();
    Ztext.Text=dt.Rows[0]["z"].ToString();
    }
    }
    

    This much of code is enough to get what you want.

提交回复
热议问题