在另一种形式上显示2个DataKeyNames(主键和外键) [英] Displaying 2 DataKeyNames(primary key and foreign key) on another form

查看:61
本文介绍了在另一种形式上显示2个DataKeyNames(主键和外键)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我在表单上有一个gridview,并且那个gridview有fields.offields中有2个我不希望它们对用户可见的字段.我所做的是删除它们,但保留了DataKeyNames ="EventsID,Id_Stadium".这些是我正在谈论的领域.Events是主键,Id_Stadium是外键.
那么我的问题是选择行时,它应该由其他表格上显示2场给我specifik信息.
我正在使用风箱式方法来执行此操作,但是在另一种形式的EventID上却分两次显示.请解决此问题!

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


}


}

推荐答案

你好

Hello

If(IsPostBack)
   Response.Redirect("BuyTicketPage.aspx");


这篇关于在另一种形式上显示2个DataKeyNames(主键和外键)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆