我设置了gridview,用户可以在其中“选择”他们想要的行,而这些行又应该通过数据库并重定向它们。但是,当我为任何给定的结果行单击“选择”时,我在此行收到错误“输入字符串格式不正确”: myEvent.EventID = Convert.ToInt32(row.Cells[0].Text); 我把这件作品拿出来,我得到了永远与 Convert 一致的错误。所以我知道它写得不正确,但我不确定如何写。任何帮助都会很棒!
抱歉,我是新手!
我的 girdview 代码:
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
Event myEvent = new Event();
GridViewRow row = GridView1.SelectedRow;
myEvent.EventID = Convert.ToInt32(row.Cells[0].Text);
myEvent.Sport = row.Cells[1].Text;
myEvent.EventName = row.Cells[2].Text;
myEvent.Section = Convert.ToInt32(row.Cells[3].Text);
myEvent.TicketsAvailable = Convert.ToInt32(row.Cells[4].Text);
myEvent.EventDate = Convert.ToDateTime(row.Cells[5].Text);
Session["myEvent"] = myEvent;
Response.Redirect("Complete.aspx");
}
如果您还需要它,我的事件代码:
public class Event
{
public int EventID { get; set; }
public string EventName { get; set; }
public string Sport { get; set; }
public int Section { get; set; }
public int TicketsAvailable { get; set; }
public DateTime EventDate { get; set; }
}