Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在gridview中选择单击时重定向_C#_Asp.net_Gridview - Fatal编程技术网

C# 在gridview中选择单击时重定向

C# 在gridview中选择单击时重定向,c#,asp.net,gridview,C#,Asp.net,Gridview,我的表单中有两个启用了选择行的GridView。有人能帮我编码吗?它可以在GridView中单击select而不是像我编码的那样单击按钮重定向到不同的表单 namespace TicketsApp { public partial class SearchTickets : System.Web.UI.Page { string connect = System.Configuration.ConfigurationManager.ConnectionString

我的表单中有两个启用了选择行的GridView。有人能帮我编码吗?它可以在GridView中单击select而不是像我编码的那样单击按钮重定向到不同的表单

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;
            }
        }
    }
}    

你到底想做什么?您是否需要在GridView中单击按钮时重定向到某个页面的功能?请详细解释。使用Gridview.SelectedIndexChanged事件如何?