hello to you please I have a little problem I have a gridview in which I applied a display condition. I would put a button returns all the lines displayed when you click on it

david 237 41 Reputation points
2022-11-19T13:17:30.637+00:00

<asp:GridView ID="Gridview1" class="mx-auto" runat="server" AutoGenerateColumns="False" OnRowDataBound="Gridview1_RowDataBound"
KeyNames="Id_Task" AllowPaging="True" PageSize="6" DataSourceID="SqlDataSource1" CellPadding="6" ForeColor="#333333" GridLines="Vertical">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="Id_Task" HeaderText="Id_Task" SortExpression="Id_Task" Visible="false" />
<asp:BoundField DataField="Taches a faire" HeaderText="Taches a faire" SortExpression="Taches a faire" />
<asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
<asp:BoundField DataField="date de requete" HeaderText="date de requete" SortExpression="date de requete" />
<asp:BoundField DataField="deadline" HeaderText="deadline" SortExpression="deadline" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:HyperLinkField Text="Details" DataNavigateUrlFields="Id_Task,Taches a faire,Username,date de requete" DataNavigateUrlFormatString="~/Admin/NewPage.aspx?Id_Task={0}&Taches a faire={1}&Username={2}&date de requete={3}" />

            </Columns>  
            <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
            <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />  
            <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />  
            <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />  
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />  
            <SortedAscendingCellStyle BackColor="#FDF5AC" />  
            <SortedAscendingHeaderStyle BackColor="#4D0000" />  
            <SortedDescendingCellStyle BackColor="#FCF6C0" />  
            <SortedDescendingHeaderStyle BackColor="#820000" />  
        </asp:GridView>  

code.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Task_ListTask : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}  
protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)  
{  
    if (e.Row.RowType == DataControlRowType.DataRow)  
    {  
        DataTable dt = new DataTable();  
        dt = (DataTable)Gridview1.DataSource;  
        int rowindex = e.Row.RowIndex;  
        e.Row.Attributes.Add("class", "customerRow");  
          
    }  
    if (e.Row.RowType == DataControlRowType.DataRow)  
    {  
        if (e.Row.Cells[5].Text.Equals("Finished"))  
        {  
            e.Row.BackColor = System.Drawing.Color.DarkGreen;  
            e.Row.ForeColor = System.Drawing.Color.White;  
            e.Row.Visible = false;  
        }  


    }  

}  



protected void Button1_Click(object sender, EventArgs e)  
{  

}  

}

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,539 questions
ASP.NET API
ASP.NET API
ASP.NET: A set of technologies in the .NET Framework for building web applications and XML web services.API: A software intermediary that allows two applications to interact with each other.
348 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Lan Huang-MSFT 29,916 Reputation points Microsoft Vendor
    2022-11-21T02:22:07.38+00:00

    Hi @david 237 ,
    You iterate over all rows and display them.

     protected void Button1_Click(object sender, EventArgs e)  
            {                        
               for (int i = 0 ; i < Gridview1.Rows.Count; i++)  
                {  
                    Gridview1.Rows[i].Visible = true;                
                }  
            }  
    

    262308-10.gif
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.