我有两个GridView
s,在我的表单中启用了选择行。有人可以帮我编码,只需点击GridView
中的选项而不是点击按钮(就像我编码的那样),它可以重定向到不同的表单吗?
namespace TicketsApp
{
public partial class SearchTickets : System.Web.UI.Page
{
string connect = System.Configuration.ConfigurationManager.ConnectionStrings["TicketsConnectionString"].ConnectionString;
ArrayList selectedSportEvent = new ArrayList();
protected void btnSearch_Click1(object sender, EventArgs e)
{
DataAccess myData = new DataAccess();
ArrayList parameters = new ArrayList();
//Updates the selected by the dates specified
SqlDataReader results;
parameters.Add(new SqlParameter("@StartDate", CalStartDate.SelectedDate));
parameters.Add(new SqlParameter("@EndDate", CalEndDate.SelectedDate));
results = myData.GetDataReader("SearchTickets", connect, parameters);
//Clear sort expression
grdSearch.DataSourceID = String.Empty;
this.grdSearch.DataSource = results;
this.grdSearch.DataBind();
//makes gridview Search visible
grdSearch.Visible = true;
grdUpdated.Visible = false;
//make sure the dates are selected
if (CalStartDate.SelectedDate < DateTime.Today || CalEndDate.SelectedDate < DateTime.Today)
{
CalStartDate.Focus();
return;
}
if (CalEndDate.SelectedDate < DateTime.Today)
{
lblCalError.Visible = true;
return;
}
}
protected void btnUpdate_Click1(object sender, EventArgs e)
{
DataAccess myData = new DataAccess();
ArrayList parameters = new ArrayList();
//updates the selection by the sport selected
SqlDataReader results;
parameters.Add(new SqlParameter("@SportName", ddlSportType.SelectedItem.ToString()));
results = myData.GetDataReader("SearchTicketsBySport", connect, parameters);
//Clear sort expression
grdUpdated.DataSourceID = String.Empty;
this.grdUpdated.DataSource = results;
this.grdUpdated.DataBind();
//Makes gridview updated visible
grdUpdated.Visible = true;
grdSearch.Visible = false;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session.Remove("EventData");
}
CalStartDate.SelectedDate = DateTime.Today;
CalEndDate.SelectedDate = DateTime.Today;
}
//Adds the item selected to the array
protected void grdSearch_SelectedIndexChanged(object sender, EventArgs e)
{
selectedSportEvent.Clear();
int x;
for (x = 1; x < grdSearch.SelectedRow.Cells.Count; x++)
{
int selectedRow = grdSearch.SelectedIndex;
GridViewRow r = grdSearch.Rows[selectedRow];
Session["EventID"] = r.Cells[1].Text;
Session["description"] = r.Cells[2].Text;
Session["ticketcost"] = r.Cells[7].Text;
Session["numtickets"] = r.Cells[6].Text;
Session["State"] = r.Cells[9].Text;
Session["Section"] = r.Cells[4].Text;
Session["Row"] = r.Cells[5].Text;
Session["date"] = r.Cells[8].Text;
}
}
//Adds the item selected to the array
protected void grdUpdated_SelectedIndexChanged(object sender, EventArgs e)
{
selectedSportEvent.Clear();
int x;
for (x = 1; x < grdUpdated.SelectedRow.Cells.Count; x++)
{
int selectedRow = grdUpdated.SelectedIndex;
GridViewRow r = grdUpdated.Rows[selectedRow];
Session["EventID"] = r.Cells[1].Text;
Session["description"] = r.Cells[2].Text;
Session["ticketcost"] = r.Cells[7].Text;
Session["numtickets"] = r.Cells[6].Text;
Session["State"] = r.Cells[9].Text;
Session["Section"] = r.Cells[4].Text;
Session["Row"] = r.Cells[5].Text;
Session["date"] = r.Cells[8].Text;
}
}
protected void btnOrderTickets_Click(object sender, EventArgs e)
{
//Redirects to TicketOrder form
Response.Redirect("TicketOrder.aspx");
}
protected void CalStartDate_DayRender(object sender, DayRenderEventArgs e)
{
if (e.Day.Date < (System.DateTime.Now.AddDays(-1)))
{
e.Day.IsSelectable = false; e.Cell.Font.Strikeout = true;
}
}
}
}