2011-06-07 70 views
-1

我有招聘項目。在這個項目中,我有一個網格視圖,其中包含所有空缺的詳細信息。隨着這個按鈕。當用戶點擊這個按鈕時,該特定空位的可用採訪時間表將在該行下方的另一個網格中可見。我所做的是將網格視圖放置在表格中,並且表格最初是不可見的。當用戶點擊圖像按鈕時,當時我試圖從網格視圖中查找表格,但無法找到它。 這是我的.aspx頁面的代碼按鈕點擊事件在gridview隱藏/顯示錶

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

請指出我的問題的代碼...

回答

相關問題