2

Hi I have a page that has a load of check boxes, when one is selected the user then clicks the button to go to a new page. I need this new page to have the ID of the record selected from the previous page in it.

I can't work out how to get the int value for the ID called FileID into the next page called EditFile.aspx.

All of my code for this function is currently inside a buttonclick event:

protected void btnEditSelectedFile_Click(object sender, EventArgs e)
{
    int intSelectedFileCount = 0;
    foreach (GridDataItem item in fileRadGrid.MasterTableView.Items)
    {
        int FileID = int.Parse(fileRadGrid.MasterTableView.DataKeyValues[item.DataSetIndex - (fileRadGrid.CurrentPageIndex * fileRadGrid.PageSize)]["FileID"].ToString()); //Gets File ID of Selected field

        CheckBox chk = (CheckBox)item["AllNone"].Controls[0];
        if (chk.Checked)
        {
            intSelectedFileCount++;

        }
    }

    if (intSelectedFileCount == 1)
    {
        Response.Redirect("EditFile.aspx", false);        
    }
    else
    {
        lblNeedSingleFile.Visible = true;
    }
}

Any help on how to access 'FileID' in EditFile page would be really appreciated!

Daniel
  • 9,491
  • 12
  • 50
  • 66

2 Answers2

3

to share data between pages in asp.net you have 2 ways:

1) using URL Query String : when your redirect you change the below line

Response.Redirect("EditFile.aspx?FileId=" + FileID.ToString(), false); 

and in the EditFile.aspx you can do in the Page_Load()

int FileId = int.Parse(Request.QueryString["FileId"]);

2) using Session State : set the session field ex:

Session["FileId"] = FileID;

and retrieve it from EditFile.aspx as

int FileId = (int)Session["FileId"];
Hany Habib
  • 1,377
  • 1
  • 10
  • 19
2

Just pass your ID as an Argument like:

Response.Redirect("EditFile.aspx?fileId=" + FileID, false);

On EditFile.aspx you can read fileId by:

string FileID = Request.QueryString["fileId"];

You need to cast this into an int of course.

int fileId = (int) FileID;
Daniel
  • 9,491
  • 12
  • 50
  • 66