0

我一直在为这个问题苦苦挣扎一整天,但我似乎没有找到答案。

我有一个名为 PickRecord.aspx 的页面,其中动态生成了“开始面试”、“编辑”和“查看记录”列,它们会将我相应地重定向到 StartInterview.aspx 或 EditViewInterview.aspx。

PickRecord.aspx - GridView 填充有受访者姓名,并生成一个按钮,单击该按钮应将我重定向到 StartInterview.aspx 并在所选记录中为我提供其他字段/信息。

StartInterview.aspx - 包含有关所选记录的附加信息,这些信息需要使用数据库中的数据进行填充。我试过查询字符串,使用 selectedIndexChanged 并且没有运气。

如果有人能指导我完成这个,我会非常感激。提前致谢!

PickRecord.aspx


<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="470px" Width="660px" HorizontalAlign="Center" SelectedIndexChanged="GridView1_SelectedIndexChanged">

    <Columns>   
        <asp:BoundField DataField="First_Name" HeaderText="First Name" ItemStyle-HorizontalAlign = "Center">    
        </asp:BoundField>   

        <asp:BoundField DataField="Last_Name" HeaderText=" Last Name" ItemStyle-HorizontalAlign = "Center" >    
        </asp:BoundField>   

        <asp:BoundField DataField="Salon_Number" HeaderText="Salon" ItemStyle-HorizontalAlign = "Center" >  
        </asp:BoundField>   

    </Columns>  
</asp:GridView> 

PickRecord.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data.SqlClient;
using System.Data;

namespace TSS.Trainer
{

    public partial class Trainer_PickRecord : System.Web.UI.Page
    {
    static string id;


    protected void Page_Load(object sender, EventArgs e)
    {
        dbConnection dbConn = new dbConnection();
        string s = Request.QueryString["mode"].ToString();

        if (!IsPostBack)
        {
            FillMonth(ddl_T_month);
            FillYear(ddl_T_year);
        }

        if (s == "a")
        {

            TemplateField tf1 = new TemplateField();
            tf1.ItemTemplate = new btntemplate1();
            tf1.HeaderText = "Start Interview";
            tf1.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            GridView1.Columns.Add(tf1);

            DataTable dtInterviewee = new DataTable();
            dtInterviewee = Salon_WebService.populateInterviewee();
            GridView1.DataSource = dtInterviewee;
            GridView1.DataBind();
        }

        else if (s == "b")
        {
            TemplateField tf2 = new TemplateField();
            TemplateField tf3 = new TemplateField();
            tf2.ItemTemplate = new btntemplate2();
            tf3.ItemTemplate = new btntemplate3();
            tf2.HeaderText = "Edit";
            tf3.HeaderText = "View";
            tf2.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            tf3.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
            GridView1.Columns.Add(tf2);
            GridView1.Columns.Add(tf3);

            DataTable dtInterviewee = new DataTable();
            dtInterviewee = Salon_WebService.populateInterviewee();
            GridView1.DataSource = dtInterviewee;
            GridView1.DataBind();
        }

         void GridView1_SelectedIndexChanged(object sender, EventArgs e)
         {
            GridViewRow row = GridView1.SelectedRow;
            id = row.Cells[0].Text;
         }

    }



    class btntemplate1 : ITemplate
    {

        public void InstantiateIn(System.Web.UI.Control container)
        {

            HyperLink h1 = new HyperLink();
            h1.NavigateUrl = "Trainer_StartInterview.aspx?x= " +id;
            h1.ImageUrl = "../Images/T_StartIV_small.png";
            container.Controls.Add(h1);
        }
    }


    class btntemplate2 : ITemplate
    {
        public void InstantiateIn(System.Web.UI.Control container)
        {

            HyperLink h2 = new HyperLink();
            h2.NavigateUrl = "Trainer_Home.aspx";
            h2.ImageUrl = "../Images/Edit_small.png";

            container.Controls.Add(h2);

        }
    }

    class btntemplate3 : ITemplate
    {
        public void InstantiateIn(System.Web.UI.Control container)
        {
            HyperLink h3 = new HyperLink();
            h3.NavigateUrl = "Trainer_ViewRecord.aspx";
            h3.ImageUrl = "../Images/View_small.png";

            container.Controls.Add(h3);
        }
    }
}

}

开始面试.aspx

<div id="T_StartInterview_formHeader" class="fh2">
        <center>
            <table>
                <tr>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblCreate_Date" runat="server" Text="Create Date : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="LabelCD" runat="server" Text="December 05, 2011 "></asp:Label>
                    </td>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblUpdate_Date" runat="server" Text="Update Date : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblUD" runat="server" Text="December 09, 2011 "></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblCreatedBy" runat="server" Text="Created By : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblCB" runat="server" Text='<%# Eval ("First_Name") %>' class="lblSizeR"></asp:Label>
                    </td>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblUpBy" runat="server" Text="Updated By : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblUB" runat="server" Text="Sharon Miller " class="lblSizeR"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblFName" runat="server" Text="First Name : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblFN" runat="server" Text="Michelle"></asp:Label>
                    </td>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblLName" runat="server" Text="Last Name : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblLN" runat="server" Text="Rusk"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblPhone" runat="server" Text="Phone : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblPh" runat="server" Text="269 123 1234"></asp:Label>
                    </td>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblEmail" runat="server" Text="E-Mail : "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblMail" runat="server" Text="xyz@visiblechanges.com" class="lblSizeR"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right; color: white">
                        <asp:Label ID="lblSalon" runat="server" Text="Salon: "></asp:Label>
                    </td>
                    <td>
                        <asp:Label ID="lblSal" runat="server" Text="Memorial City Mall" class="lblSizeR"></asp:Label>
                    </td>
                </tr>
            </table>

Trainer_StartInterview.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace TSS.Trainer
{
public partial class Trainer_StartInterview : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string s = Request.QueryString["id"].ToString();
    }
}

}

4

1 回答 1

0

您没有提到确切的问题,但是如果您甚至没有点击 StartInterview.aspx 页面,那么我建议您删除代码中的复杂实例化,并将其替换为具有按钮甚至按钮列的简单基于模板的列。您可以检查此链接的实现:单击gridview按钮字段时重定向到特定页面

于 2012-04-16T17:54:39.960 回答