Click here to Skip to main content
15,886,067 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to show grid view when checkbox is checked..i have tried but it is not coming

my code is

Default.aspx


<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" AutoPostBack="true"/><asp:GridView
ID="GridView1" runat="server" AutoGenerateColumns="False" Visible="false"
DataSourceID="SqlDataSource1" >
<columns> <asp:BoundField DataField="Iname" HeaderText="Iname" SortExpression="Iname" />
<asp:BoundField DataField="courses" HeaderText="courses"
SortExpression="courses" />
<asp:BoundField DataField="fees" HeaderText="fees" SortExpression="fees" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:peersConnectionString %>"
SelectCommand="SELECT * FROM [pubs]">




Default.cs


protected void Page_Load(object sender, EventArgs e)
{
GridView1.DataBind();
}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
GridView1.Visible = false;
}
}
}

and i have data in pubs table
Posted
Updated 19-Jan-15 18:43pm
v2
Comments
Thanks7872 19-Jan-15 5:05am    
And what is your question? This is just your requirement,not question. What have you trie so far? Did you try using google?
Member 11382784 19-Jan-15 5:13am    
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
GridView1.Visible = true;
}
}


...i cant find answer in google
So, what is the issue here? I hope, GridView has data.
Member 11382784 19-Jan-15 5:55am    
Yes gridview has data..but when i click checkbox it is not displaying

<div>
<asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged="CheckBox1_CheckedChanged" /><asp:GridView
ID="GridView1" runat="server" AutoGenerateColumns="False" Visible="false"
DataSourceID="SqlDataSource1" >
<columns>
<asp:BoundField DataField="Iname" HeaderText="Iname" SortExpression="Iname" />
<asp:BoundField DataField="courses" HeaderText="courses"
SortExpression="courses" />
<asp:BoundField DataField="fees" HeaderText="fees" SortExpression="fees" />


<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:peersConnectionString %>"
SelectCommand="SELECT * FROM [pubs]">
</div>
What are you doing inside the Page load Event?

1 solution

you should handle the post back , on your page load you are biding again , which means refresh the grid view with default values then it will go to your button code , so the code of your page load will be :
C#
protected void Page_Load(object sender, EventArgs e)
{


 if (!IsPostBack)
    {
        // Validate initially to force asterisks
        // to appear before the first roundtrip.
       GridView1.DataBind();
    }
 

}
 
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