I have my gridview set where the user can “select” the row they want which in turn should go through the database and redirect them. However, when I click on “select” for any given row of results I get the error “Input string was not in correct format” at this line: myEvent.EventID = Convert.ToInt32(row.Cells[0].Text); I took this piece out and I get the error for ever line with the Convert in it. So I know it’s not written correctly but I’m unsure how to write it. Any help would be great!
sorry I’m new at this!
My code for the 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");
}
My code for the Event in case you need it also:
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; }
}
Just check weather the Value that you are converting is not null. try to debug the code and check what are the values you are getting from that particular row.
another thing is if you have created generated Select Button in the gridview then the position of that select button is at 0 cell of gridview. so you can try your code like this.