locked
Hide ASP:TEMPLATEFIELD On Dropdown Selected Value RRS feed

  • Question

  • User12812739 posted
    <asp:GridView ID="grd_AcceptJobRequestFromCompany" Width="100%" AutoGenerateColumns="false"
            CssClass="table table-bordered table-condensed" runat="server"
            ShowHeaderWhenEmpty="True" HeaderStyle-ForeColor="White">
            <Columns>
             <asp:BoundField DataField="JOB_LIST_IDD" SortExpression="JOB_LIST_IDD" />
             <asp:BoundField DataField="JOB_ID" HeaderText="<%$ Resources:hr_language, lbl_JOB_ID %>" SortExpression="JOB_ID" Visible="false" />
             <asp:BoundField DataField="JOB_NAME" HeaderText="<%$ Resources:hr_language, JOB_NAME %>" SortExpression="JOB_NAME" />
             <asp:BoundField DataField="ESTNAME" HeaderText="<%$ Resources:hr_language, lbl_ESTNAME %>" SortExpression="ESTNAME" />
             <asp:BoundField DataField="DATAR" HeaderText="<%$ Resources:hr_language, lbl_ArabicDate %>" SortExpression="DATAR" DataFormatString="{0:dd/MM/yyyy}" />
             <asp:BoundField DataField="DATEN" HeaderText="<%$ Resources:hr_language, EnglishDate %>" SortExpression="DATEN" DataFormatString="{0:dd/MM/yyyy}" />
             <asp:BoundField DataField="REMARK" HeaderText="<%$ Resources:hr_language, REMARK %>" SortExpression="REMARK" />
             <asp:BoundField DataField="ADATE" HeaderText="<%$ Resources:hr_language, ADATE %>" SortExpression="ADATE" DataFormatString="{0:dd/MM/yyyy}" />
    
             <asp:TemplateField>
              <ItemTemplate>
               <asp:LinkButton ID="btn_ViewDetails" CssClass="btn btn-sm btn-info" OnClick="btn_ViewDetails_Click"
                CommandName="ViewDetails"
                CommandArgument='<%#Eval("JOB_LIST_IDD").ToString%>'
                runat="server">
              <i class="fa fa-search"></i>
              تفصيل
               </asp:LinkButton>
              </ItemTemplate>
              <ItemStyle HorizontalAlign="Center" />
             </asp:TemplateField>
    
             <asp:TemplateField>
              <ItemTemplate>
               <asp:LinkButton ID="btn_AddRemarks" CssClass="btn btn-sm btn-success"
                CommandName="FileCommand"
                CommandArgument='<%#Eval("JOB_LIST_IDD").ToString + "," + Eval("JOB_ID").ToString + "," + Eval("REMARK").ToString %>'
                OnClick="btn_AddRemarks_Click" runat="server">
              <i class="fa fa-check"></i>
              قبول
               </asp:LinkButton>
              </ItemTemplate>
              <ItemStyle HorizontalAlign="Center" />
             </asp:TemplateField>
    
             <asp:TemplateField>
              <ItemTemplate>
               <asp:LinkButton ID="btn_DeclineJobRequest" CssClass="btn btn-sm btn-danger"
                CommandName="FileCommand" OnClick="btn_DeclineJobRequest_Click"
                CommandArgument='<%#Eval("JOB_LIST_IDD").ToString + "," + Eval("JOB_ID").ToString + "," + Eval("REMARK").ToString %>'
                runat="server">
              <i class="fa fa-times"></i>
              رفض
               </asp:LinkButton>
              </ItemTemplate>
              <ItemStyle HorizontalAlign="Center" />
             </asp:TemplateField>
            </Columns>
           </asp:GridView>

    Above Is My GRID VIEW.

    <asp:DropDownList ID="dd_LastRejectList" CssClass="form-control select-sm" runat="server" AutoPostBack="True">
            <asp:ListItem Value="2">--- Select ---</asp:ListItem>
            <asp:ListItem Value="0">Show Pending Approval</asp:ListItem>
            <asp:ListItem Value="1">Recent Rejected List</asp:ListItem>
           </asp:DropDownList>

    And I Need By Default "btn_ViewDetails" Needs To Be Hide. But When I Select "Show Pending Approval" From DropDownList. <g class="gr_ gr_150 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling multiReplace" id="150" data-gr-id="150">Its</g> Shows In GridView.

    Please Help Achieve This.

    Monday, November 12, 2018 5:33 AM

All replies

  • User61956409 posted

    Hi merajgulf,

    And I Need By Default "btn_ViewDetails" Needs To Be Hide. But When I Select "Show Pending Approval" From DropDownList. Its Shows In GridView.

    To achieve your requirement, you can try:

    1) Set Visible property of asp:LinkButton "btn_ViewDetails" to false.

    <asp:TemplateField>
        <ItemTemplate>
            <asp:LinkButton ID="btn_ViewDetails" CssClass="btn btn-sm btn-info" OnClick="btn_ViewDetails_Click"
                CommandName="ViewDetails"
                CommandArgument='<%#Eval("Field2").ToString()%>'
                runat="server" Visible="false"><i class="fa fa-search"></i>تفصيل
            </asp:LinkButton>
        </ItemTemplate>
        <ItemStyle HorizontalAlign="Center" />
    </asp:TemplateField>

    2) Dynamically find asp:LinkButton "btn_ViewDetails" control from GridView rows and set Visible property based on the selected value in asp:DropDownList control OnSelectedIndexChanged event.

    <asp:DropDownList ID="dd_LastRejectList" CssClass="form-control select-sm" runat="server" AutoPostBack="True" OnSelectedIndexChanged="dd_LastRejectList_SelectedIndexChanged">
        <asp:ListItem Value="2">--- Select ---</asp:ListItem>
        <asp:ListItem Value="0">Show Pending Approval</asp:ListItem>
        <asp:ListItem Value="1">Recent Rejected List</asp:ListItem>
    </asp:DropDownList>
    Protected Sub dd_LastRejectList_SelectedIndexChanged(sender As Object, e As EventArgs)
        If dd_LastRejectList.SelectedValue = "0" Then
            For Each row As GridViewRow In grd_AcceptJobRequestFromCompany.Rows
                row.FindControl("btn_ViewDetails").Visible = True
            Next
        Else
            For Each row As GridViewRow In grd_AcceptJobRequestFromCompany.Rows
                row.FindControl("btn_ViewDetails").Visible = False
            Next
        End If
    End Sub

    With Regards,

    Fei Han

    Tuesday, November 13, 2018 2:39 AM