C# 按钮单击事件时在gridview中隐藏/显示表格

C# 按钮单击事件时在gridview中隐藏/显示表格,c#,.net,asp.net,gridview,C#,.net,Asp.net,Gridview,我有一个关于招聘的项目。在这个项目中,我有一个表格视图,其中包含所有空缺的详细信息。除此之外还有一个按钮。当用户单击此按钮时,该行下方的另一个网格中将显示该特定空缺的可用面试时间表。我所做的是将网格视图放置在表中,表最初是不可见的。当用户单击图像按钮时,当时我试图从网格视图中查找表,但找不到。 这是我的.aspx页面的代码 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server"

我有一个关于招聘的项目。在这个项目中,我有一个表格视图,其中包含所有空缺的详细信息。除此之外还有一个按钮。当用户单击此按钮时,该行下方的另一个网格中将显示该特定空缺的可用面试时间表。我所做的是将网格视图放置在表中,表最初是不可见的。当用户单击图像按钮时,当时我试图从网格视图中查找表,但找不到。 这是我的.aspx页面的代码

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<table class="formtTbl" width="100%">
    <tr>
        <td width="10%">
            &nbsp;
        </td>
        <td>
            &nbsp;</td>
        <td width="10%">
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td align="center" class="tdtitle">
            Open vacancies
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
        <asp:ImageButton ID="addVacancyBtn" runat="server" 
            ImageUrl="~/Resources/add.png" onclick="addVacancyBtn_Click" />
            &nbsp;
            Add New Vacancy</td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            <asp:GridView ID="VacancyGrid" runat="server" CssClass="mGrid" 
                AutoGenerateColumns="False" onrowcommand="VacancyGrid_RowCommand">
                <AlternatingRowStyle CssClass="alt" />
                <Columns>
                 <asp:TemplateField>
                     <ItemTemplate>
                        <asp:ImageButton ID="ScheduleBtn" runat="server" 
                         ImageUrl="~/Resources/01.gif"  
                         ToolTip="View Interview Schedule" Width="20px"
                         CommandName="View Schedule" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
                     </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="VacId" DataField="VacId" />
                    <asp:BoundField HeaderText="Title" DataField="VacTitle" />
                    <asp:BoundField HeaderText="Open" DataField="TotalOpening" />
                    <asp:BoundField HeaderText="Criteria" DataField="criteria" />
                    <asp:BoundField HeaderText="Key Skills" DataField="KeySkills" />
                    <asp:BoundField HeaderText="Exp" DataField="RequiredExperience" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:ImageButton ID="editBtn" runat="server" 
                                ImageUrl="~/Resources/art-knife.png" Width="20px" 
                                CommandName="Edit" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
                        </ItemTemplate>
                        <EditItemTemplate>
                            Edit
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Label ID="statusLbl" runat="server" Text="Label"></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <ItemTemplate>
                        <table id="ScheduleTable" visible="false">
                        <tr id="abc" visible="false"> 
                          <td colspan="10">
                            <asp:GridView ID="scheduleGrid" runat="server" Visible="False" 
                                  AutoGenerateColumns="False" onrowcommand="scheduleGrid_RowCommand">
                            <Columns>
                            <asp:BoundField DataField="VacId" HeaderText="ID" />
                           <asp:BoundField DataField="VacTitle" HeaderText="Title" />
                            <asp:BoundField DataField="InterviewTime" HeaderText="Interview Date & Time" />
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:ImageButton ID="viewIntervieweesBtn" runat="server" 
                                            ImageUrl="~/Resources/document.png" ToolTip="View interiviewees" Width="20px" 
                                            CommandName="View Interviewees" CommandArgument="<%#((GridViewRow)Container).RowIndex %>"/>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                            </asp:GridView>
                            <asp:Label ID="ScheduleNotifyLbl" runat="server" Visible="false"></asp:Label>
                           </td>
                        </tr>
                        </table>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle CssClass="pgr" />
            </asp:GridView>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td align="left">
            <asp:Label ID="notificationLbl" runat="server" Font-Size="X-Large" 
                ForeColor="Red" Text="Label" Visible="False"></asp:Label>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
        <td>
            &nbsp;</td>
    </tr>
    </table>
</asp:Content>

空缺
增加新空缺
编辑
//这是我的.aspx.cs页面的代码

public partial class Department_VacancyList : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
    DataTable VacancyTable = null;
    try
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["status"] != null)
            {
                // strStatus = Request.QueryString["status"];
                Session.Add("strStatus", Request.QueryString["status"]);
            }
            if (Session["OpResult"] != null)
            {
                notificationLbl.Visible = true;
                if (Session["OpResult"].ToString() == "InsertSuceess")
                    notificationLbl.Text = "New Vacancy Has Been Created Successfully";
                if (Session["OpResult"].ToString() == "InsertFail")
                    notificationLbl.Text = "An Error Occured While Creating New Vacancy..";
                if (Session["OpResult"].ToString() == "EditSuccess")
                    notificationLbl.Text = "Your Changes Has Been Saved Successfully";
                if (Session["OpResult"].ToString() == "EditFail")
                    notificationLbl.Text = "An Error Occured While Saving Changes...";
            }
            using (VacancyMasterClass VacMaster = new VacancyMasterClass())
            {
                if (Session["strStatus"].ToString() == "1")//All Vacancies
                    VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1");//Change Here.
                else if (Session["strStatus"].ToString() == "2")//Open Vacancies
                    VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1 and Status=0");//Change Here.
                else if (Session["strStatus"].ToString() == "3")//Closed Vacancies
                    VacancyTable = VacMaster.getTable("and DeptId=1 and CompId=1 and Status=1");//Change Here.
                VacancyGrid.DataSource = VacancyTable;
                VacancyGrid.DataBind();
                VacancyGrid.ControlStyle.Width = 650;
                VacancyGrid.Columns[0].ItemStyle.Width = 20;
                VacancyGrid.Columns[1].ItemStyle.Width = 10;
                VacancyGrid.Columns[2].ItemStyle.Width = 150;
                VacancyGrid.Columns[3].ItemStyle.Width = 20;
                VacancyGrid.Columns[4].ItemStyle.Width = 190;
                VacancyGrid.Columns[5].ItemStyle.Width = 190;
                VacancyGrid.Columns[6].ItemStyle.Width = 20;
                VacancyGrid.Columns[7].ItemStyle.Width = 30;
                VacancyGrid.Columns[8].ItemStyle.Width = 30;
                VacancyGrid.Columns[9].ItemStyle.Width = 0;
                VacancyGrid.Columns[1].Visible = false;
                if (Session["strStatus"].ToString() == "1" || Session["strStatus"].ToString() == "3")
                {
                    VacancyGrid.Columns[7].Visible = false;
                    VacancyGrid.Columns[0].Visible = false;
                    for (int intRowcount = 0; intRowcount < VacancyTable.Rows.Count; intRowcount++)
                    {
                        Label StatusLbl = (Label)VacancyGrid.Rows[intRowcount].Cells[6].FindControl("statusLbl");
                        if (VacancyTable.Rows[intRowcount]["Status"].ToString() == "False")
                        {
                            StatusLbl.ForeColor = Color.Green;
                            StatusLbl.Text = "Open";
                        }
                        else
                        {
                            StatusLbl.ForeColor = Color.Red;
                            StatusLbl.Text = "Closed";
                        }
                    }
                }
                else if (Session["strStatus"].ToString() == "2")
                    VacancyGrid.Columns[8].Visible = false;
            }      
        }
    }
    catch (Exception ex)
    {
        CommonProcedures.WriteErrorLog("Department_VacancyList", "Page_Load", ex.Message);
    }
    finally
    {
        Session.Remove("OpResult");
    }
}
//protected void VacancyGrid_RowEditing(object sender, GridViewEditEventArgs e)
//{
//    int intOpMode = 2;//Edit Mode
//    int intVacId = Convert.ToInt32(VacancyGrid.Rows[e.NewEditIndex].Cells[1].Text);
//    Response.Redirect("create_vacancyfrm.aspx?VacId="+intVacId+"&OpMode="+intOpMode);
//}
protected void addVacancyBtn_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
    int intOpMode = 1;//Edit Mode
    int intVacId = 0;
    Response.Redirect("create_vacancyfrm.aspx?DeptId=1&CompId=1&VacId=" + intVacId + "&OpMode=" + intOpMode);//Change Here
}
protected void VacancyGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
    DataTable InterviewScheduleTable = null;
    int intVacid = 0;
    try
    {
        if (e.CommandName == "View Schedule")
        {

            int intRowIndex = Convert.ToInt32(e.CommandArgument);
            GridViewRow Row = VacancyGrid.Rows[intRowIndex];
            //Table ScheduleTable = (Table)Row.FindControl("ScheduleTable");
            intVacid = Convert.ToInt32(Row.Cells[1].Text);
            GridView scheduleGrid = (GridView)Row.FindControl("scheduleGrid");
            Label ScheduleNotifyLbl = (Label)Row.FindControl("ScheduleNotifyLbl");

            if (scheduleGrid.Visible == false)
            {
                using (vwVacInterviewShcedule oInterviewSchedule = new vwVacInterviewShcedule())
                {
                    InterviewScheduleTable = oInterviewSchedule.getTable("and VacId=" + intVacid);
                    if (InterviewScheduleTable.Rows.Count > 0)
                    {
                        scheduleGrid.Visible = true;
                        scheduleGrid.DataSource = InterviewScheduleTable;
                        scheduleGrid.DataBind();
                        scheduleGrid.ControlStyle.Width = 650;
                        scheduleGrid.Columns[0].ItemStyle.Width = 10;
                        scheduleGrid.Columns[1].ItemStyle.Width = 300;
                        scheduleGrid.Columns[2].ItemStyle.Width = 250;
                        scheduleGrid.Columns[3].ItemStyle.Width = 90;
                    }
                    else
                    {
                        if (ScheduleNotifyLbl.Visible == false)
                        {
                            ScheduleNotifyLbl.Visible = true;
                            ScheduleNotifyLbl.Text = "Interview is yet to schedyule for this vacancy";
                        }
                        else
                        {
                            ScheduleNotifyLbl.Visible = false;
                        }
                    }
                }
            }
            else
            {
                scheduleGrid.Visible = false;
            }

        }
        ViewState.Add("VacId", intVacid);
        if (e.CommandName == "Edit")
        {
            int intOpMode = 2;
            int intRowIndex = Convert.ToInt32(e.CommandArgument);
            GridViewRow Row = VacancyGrid.Rows[intRowIndex];
            int intVacId = Convert.ToInt32(Row.Cells[1].Text);
            Response.Redirect("create_vacancyfrm.aspx?VacId=" + intVacId + "&OpMode=" + intOpMode);
        }
    }
    catch (Exception ex)
    {
        CommonProcedures.WriteErrorLog("Department_VacancyList", "VacancyGrid_RowCommand", ex.Message);
    }
    finally
    {
        InterviewScheduleTable = null;
    }
}

 protected void scheduleGrid_RowCommand(object sender, GridViewCommandEventArgs e)
 {
    try
    {
        foreach (GridViewRow Row in VacancyGrid.Rows)
        {
            GridView ScheduleGrid = (GridView)Row.FindControl("scheduleGrid");
            if (e.CommandName == "View Interviewees")
            {
                int intRowIndex = Convert.ToInt32(e.CommandArgument);
                GridViewRow ScheduleGridRow = ScheduleGrid.Rows[intRowIndex];
                int intVacId = Convert.ToInt32(ScheduleGridRow.Cells[3].Text);
                Session.Add("Time",ScheduleGridRow.Cells[2].Text);
                Response.Redirect("~/Department Head/Schedulefrm.aspx?VacId="+intVacId);
            }
        }
    }
    catch (Exception ex)
    {
        CommonProcedures.WriteErrorLog("Department_VacancyList", "scheduleGrid_RowCommand", ex.Message);
      }
   }
}
公共部分类部门\u VacancyList:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
DataTable VacancyTable=null;
尝试
{
如果(!IsPostBack)
{
if(Request.QueryString[“status”!=null)
{
//strStatus=Request.QueryString[“status”];
Session.Add(“strStatus”,Request.QueryString[“status”]);
}
如果(会话[“操作结果”]!=null)
{
notificationLbl.Visible=真;
if(会话[“操作结果”].ToString()=“插入成功”)
notificationLbl.Text=“新空缺已成功创建”;
if(会话[“操作结果”].ToString()=“InsertFail”)
notificationLbl.Text=“创建新空缺时出错..”;
if(会话[“操作结果”].ToString()=“编辑成功”)
notificationLbl.Text=“您的更改已成功保存”;
if(会话[“操作结果”].ToString()=“编辑失败”)
notificationLbl.Text=“保存更改时出错…”;
}
使用(VacancyMasterClass VacMaster=new VacancyMasterClass())
{
if(Session[“strStatus”].ToString()=“1”)//所有空缺
VacancyTable=VacMaster.getTable(“和DeptId=1和CompId=1”);//在此处更改。
else if(Session[“strStatus”].ToString()=“2”)//打开空缺
VacancyTable=VacMaster.getTable(“且DeptId=1且CompId=1且Status=0”);//在此处更改。
else if(Session[“strStatus”].ToString()=“3”)//已关闭的空缺
VacancyTable=VacMaster.getTable(“且DeptId=1且CompId=1且Status=1”);//在此处更改。
VacancyGrid.DataSource=VacancyTable;
VacancyGrid.DataBind();
VacancyGrid.ControlStyle.Width=650;
VacancyGrid.Columns[0].ItemStyle.Width=20;
VacancyGrid.Columns[1].ItemStyle.Width=10;
VacancyGrid.Columns[2].ItemStyle.Width=150;
VacancyGrid.Columns[3].ItemStyle.Width=20;
VacancyGrid.Columns[4].ItemStyle.Width=190;
VacancyGrid.Columns[5].ItemStyle.Width=190;
VacancyGrid.Columns[6].ItemStyle.Width=20;
VacancyGrid.Columns[7].ItemStyle.Width=30;
VacancyGrid.Columns[8].ItemStyle.Width=30;
VacancyGrid.Columns[9].ItemStyle.Width=0;
VacancyGrid.Columns[1]。Visible=false;
if(Session[“strStatus”].ToString()=“1”| | Session[“strStatus”].ToString()=“3”)
{
VacancyGrid.Columns[7].Visible=false;
VacancyGrid.Columns[0]。Visible=false;
对于(int intRowcount=0;intRowcount