locked
hide "add" linkbutton when i click to "edit" linkbutton" RRS feed

  • Question

  • User-381059448 posted

    hi,

    i like to set the visibility of add linkbutton to false when i click to edit linkbutton :

    this is my form code :

    <asp:TemplateField  HeaderStyle-Width="50px">  
      
        <ItemTemplate>  
     <asp:LinkButton ID="link_edit" runat="server" CommandName="edit" ToolTip="edit" Text="<span class='table-icons'><i class='fas fa-edit'></i></span>" style="width:20px"></asp:LinkButton>  
      
     <asp:LinkButton ID="link_delete" runat="server" CommandName="delete" ToolTip="delete" Text="<span class='table-icons'><i class='fas fa-times'></i></span>" style="width:20px;" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>  
      
      </ItemTemplate>  
      
     <EditItemTemplate>  
    <asp:LinkButton ID="link_update" runat="server" CommandName="Update" ToolTip="Update" Text="<span class='table-icons'><i class='far fa-save'></i></span>" style="width:20px;"></asp:LinkButton>  
      
    <asp:LinkButton ID="link_cancel" runat="server" CommandName="Cancel" ToolTip="cancel" Text="<span class='table-icons'><i class='fas fa-times'></i></span>" style="width:20px;"></asp:LinkButton>  
                                                                                  
    </EditItemTemplate>  
      
                                                                                  
    <HeaderTemplate>  
                                                   
     <label style="color: #3366FF">Action</label>                                                                                  
    <asp:LinkButton ID="link_add" runat="server" ValidationGroup="company_country" CausesValidation="true" CommandName="addnew" ToolTip="addnew" Text="<span class='table-icons' style='font-size:15pt;'><i class='far fa-save'></i></span>"></asp:LinkButton>  
                                                                                 
     </HeaderTemplate>  
                                                                             
     </asp:TemplateField>  

    and this is my function that i would define invisible = false 

    protected void GridView_cause_RowEditing(object sender, GridViewEditEventArgs e)  
            {  
                GridView_cause.EditIndex = e.NewEditIndex;  
                PARAM_CAUSE_DEPARTURE_DAO cause = new PARAM_CAUSE_DEPARTURE_DAO(this._sSqlConnectionString);  
                display_cause();  
                cause.edit(GridView_cause);  
                display_cause_form();  
            }  

    help me please 

    Sunday, September 30, 2018 2:57 PM

Answers

  • User61956409 posted

    Hi ahmedshpt,

    i like to set the visibility of add linkbutton to false when i click to edit linkbutton

    To achieve your requirement, please refer to the following sample code.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField HeaderText="ID" DataField="ID" />
            <asp:BoundField HeaderText="Name" DataField="Name" />
            <asp:TemplateField HeaderStyle-Width="50px">
                <ItemTemplate>
                    <asp:LinkButton ID="link_edit" runat="server" CommandName="edit" ToolTip="edit" Text="Edit" Style="width: 20px"></asp:LinkButton>
                    <asp:LinkButton ID="link_delete" runat="server" CommandName="delete" ToolTip="delete" Text="Delete" Style="width: 20px;" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>
                </ItemTemplate>
    
                <EditItemTemplate>
                    <asp:LinkButton ID="link_update" runat="server" CommandName="Update" ToolTip="Update" Text="Update" Style="width: 20px;"></asp:LinkButton>
                    <asp:LinkButton ID="link_cancel" runat="server" CommandName="Cancel" ToolTip="cancel" Text="Cancel" Style="width: 20px;"></asp:LinkButton>
                </EditItemTemplate>
                <HeaderTemplate>
                    <label style="color: #3366FF">Action</label>
                    <asp:LinkButton ID="link_add" runat="server" ValidationGroup="company_country" CausesValidation="true" CommandName="addnew" ToolTip="addnew" Text="Add"></asp:LinkButton>
                </HeaderTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
    
        bindgrid();
    }
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        var editrowindex = GridView1.EditIndex;
        if (e.Row.RowType == DataControlRowType.Header && editrowindex > -1)
        {
            e.Row.FindControl("link_add").Visible = false;
        }
    }

    Test Result:

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 1, 2018 7:17 AM

All replies

  • User61956409 posted

    Hi ahmedshpt,

    i like to set the visibility of add linkbutton to false when i click to edit linkbutton

    To achieve your requirement, please refer to the following sample code.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowEditing="GridView1_RowEditing" OnRowDataBound="GridView1_RowDataBound">
        <Columns>
            <asp:BoundField HeaderText="ID" DataField="ID" />
            <asp:BoundField HeaderText="Name" DataField="Name" />
            <asp:TemplateField HeaderStyle-Width="50px">
                <ItemTemplate>
                    <asp:LinkButton ID="link_edit" runat="server" CommandName="edit" ToolTip="edit" Text="Edit" Style="width: 20px"></asp:LinkButton>
                    <asp:LinkButton ID="link_delete" runat="server" CommandName="delete" ToolTip="delete" Text="Delete" Style="width: 20px;" OnClientClick="return confirm('Are you sure you want to delete this record?');"></asp:LinkButton>
                </ItemTemplate>
    
                <EditItemTemplate>
                    <asp:LinkButton ID="link_update" runat="server" CommandName="Update" ToolTip="Update" Text="Update" Style="width: 20px;"></asp:LinkButton>
                    <asp:LinkButton ID="link_cancel" runat="server" CommandName="Cancel" ToolTip="cancel" Text="Cancel" Style="width: 20px;"></asp:LinkButton>
                </EditItemTemplate>
                <HeaderTemplate>
                    <label style="color: #3366FF">Action</label>
                    <asp:LinkButton ID="link_add" runat="server" ValidationGroup="company_country" CausesValidation="true" CommandName="addnew" ToolTip="addnew" Text="Add"></asp:LinkButton>
                </HeaderTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
    
        bindgrid();
    }
    
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        var editrowindex = GridView1.EditIndex;
        if (e.Row.RowType == DataControlRowType.Header && editrowindex > -1)
        {
            e.Row.FindControl("link_add").Visible = false;
        }
    }

    Test Result:

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, October 1, 2018 7:17 AM
  • User-381059448 posted

    tahnks a lot its works

    Monday, October 1, 2018 7:37 PM