Скрыть / показать таблицу в виде сетки при событии нажатия кнопки - PullRequest
0 голосов
/ 07 июня 2011

У меня есть проект по набору персонала. В этом проекте в одной форме у меня есть вид сетки, который содержит детали всех вакансий.Наряду с этим есть кнопка.Когда пользователь нажимает эту кнопку, доступное расписание собеседований для этой конкретной вакансии будет отображаться в другой сетке под этой строкой.То, что я сделал, я поместил вид сетки в таблицу, и таблица изначально невидима.Когда пользователь нажимает на кнопку с изображением, в то время я пытался найти таблицу из таблицы, но ее не удалось найти.Вот код моей страницы .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);
      }
   }
}

Пожалуйста, покажите мне мою проблему ...

1 Ответ

1 голос
/ 07 июня 2011

Вы предоставили слишком много кода, который не может быть легко прочитан.Вы должны сузить это до определенной точки.

Позвольте мне попытаться помочь вам в вашей конкретной проблеме.

Если вы установите элемент управления visible=false, он не будет отображаться на стороне клиента, и вы не сможете сделать этот элемент управления видимым позже всторона клиента.Посмотрите на эту похожую ветку, чтобы получить представление о том, как действовать: Хотите сделать видимость действительной со стороны клиента элемента управления, который стал невидимым со стороны сервера

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...