C# .NET - Displaying 2 DataKeyNames(primary key and foreign key)

Asked By Daniel on 05-Mar-12 04:34 PM
Hi!I have a gridview on my form and that gridview has fields.Among the fields there 2 fields that I dont want them to be visible to the user.What I ve did is to delete them but it keep DataKeyNames="EventsID,Id_Stadium".Those are the fieds that I am talkin about.Events is a primary key and Id_Stadium is foreign key.
then my problem is when selecting a row it should give me the specifik information by displaying the 2 fields on the other form.
I am using the bellow method to do that.But It dispaly  on the other form the EventID 2 times.Help fixing that!
 
protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
    {
      int newIndex = e.NewSelectedIndex;//Row that the user is selecting(!e is a parameter)
      object EventID = GridView1.DataKeys[newIndex].Value;
      object stadiumID = GridView1.DataKeys[newIndex].Value;
       string Game = GridView1.Rows[newIndex].Cells[0].Text;
      string Location = GridView1.Rows[newIndex].Cells[1].Text;
      string Stadium = GridView1.Rows[newIndex].Cells[2].Text;
      string Date = GridView1.Rows[newIndex].Cells[3].Text;
      string Hour = GridView1.Rows[newIndex].Cells[4].Text;
      Session["data"]= string.Format("Event:{0}<br/>Location:{1}<br/>Stadium name:{2}<br/>Date:{3}", Game, Location, Stadium, Date);
      Session["StadeID"] = stadiumID;
      Session["EventID"] = EventID;
      Response.Redirect("BuyTicketPage.aspx");
    }


Anandh Ramanujam replied to Daniel on 06-Mar-12 06:12 AM
Change the code like this...


protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {
    int newIndex = e.NewSelectedIndex;//Row that the user is selecting(!e is a parameter)
    object EventID = GridView1.DataKeys[newIndex].Value[0];
    object stadiumID = GridView1.DataKeys[newIndex].Value[1];
     string Game = GridView1.Rows[newIndex].Cells[0].Text;
    string Location = GridView1.Rows[newIndex].Cells[1].Text;
    string Stadium = GridView1.Rows[newIndex].Cells[2].Text;
    string Date = GridView1.Rows[newIndex].Cells[3].Text;
    string Hour = GridView1.Rows[newIndex].Cells[4].Text;
    Session["data"]= string.Format("Event:{0}<br/>Location:{1}<br/>Stadium name:{2}<br/>Date:{3}", Game, Location, Stadium, Date);
    Session["StadeID"] = stadiumID;
    Session["EventID"] = EventID;
    Response.Redirect("BuyTicketPage.aspx");
  }