Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In my Grid view i have 30 columns i need to show the 10 columns when page display ofter Reset button click all the 30 columns need to be displayed. How can i write the code for this scenario
Posted
Comments
Prakriti Goyal 24-Jul-14 6:05am    
You need to show 10 columns or rows?
shaikkarim 6-Aug-14 7:16am    
i need to show the 10 columns as well as 10columns data means row data

You can hide the column by visible property

and during refresh page you can call it as True

C#
GridView1.Columns[1].Visible=true;


and you can put loop for visible true or false
C#
foreach (GridViewRow gvr in gv.Rows)
       {
           //here specify cell you want to hide
           //also you may put any conditions
           gvr.Cells[0].Visible = false; // Hide cell
       }

Please check following links

http://stackoverflow.com/questions/17481250/conditionally-show-hide-asp-net-gridview-column[^]

Show / Hide GridView Columns in ASP.NET[^]
 
Share this answer
 
In Page load what Gridview columns you want just set visible true remaining are set to false.In Button Click Set visible true to all columns .
in Design mode declare a gridview like
<asp:gridview id="GridView1" runat="server" autogeneratecolumns="false" xmlns:asp="#unknown">
<columns> <asp:boundfield accessibleheadertext="ID" datafield="ID" headertext="ID">
<asp:boundfield accessibleheadertext="NAME" datafield="NAME" headertext="NAME">
<asp:boundfield accessibleheadertext="ADDRESS" datafield="ADDRESS" headertext="ADDRESS">
<asp:boundfield accessibleheadertext="PHONE" datafield="PHONE" headertext="PHONE">



in csfile:


protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
if (dt.Columns.Count == 0)
{
dt.Columns.Add("ID");
dt.Columns.Add("NAME");
dt.Columns.Add("ADDRESS");
dt.Columns.Add("PHONE");
}
DataRow dr;
for (int i = 0; i < 10; i++)
{
dr = dt.NewRow();
dr["ID"] = "ID" + i;
dr["NAME"] = "NAME" + i;
dr["ADDRESS"] = "ADDRESS" + i;
dr["PHONE"] = "PHONE" + i;
dt.Rows.Add(dr);
}
GridView1.DataSource = dt;
GridView1.DataBind();


GridView1.Columns[3].Visible = false;


}
protected void Button1_Click(object sender, EventArgs e)
{
if (GridView1.Columns.Count > 0)
{
GridView1.Columns[3].Visible = true ;

}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900