Click here to Skip to main content
14,640,678 members
Rate this:
Please Sign up or sign in to 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?
Jeet Gupta 19-Jan-15 6:11am
   
first try to check whether the data is binding on the gridview or not. then use visible false option.
Member 11382784 19-Jan-15 6:11am
   
protected void Page_Load(object sender, EventArgs e)
{

}
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
if (CheckBox1.Checked)
{
GridView1.Visible = true;
}
}
Jeet Gupta 19-Jan-15 6:35am
   
check SELECT * FROM [pubs], any data is coming for not and also check those data is binding to the gridview or not.
first make the gridview visible =TRUE, then check the gridview binds with the data or not.
Member 11382784 19-Jan-15 7:10am
   
data is binding to gridview there is no problem
   
Yes, Jeet is correct. First check if the GridView has data or not. Make it visible true and see if it is loading correctly or not.
LLLLGGGG 19-Jan-15 14:49pm
   
Please, update your question with the code written in the comments in order to get other users not to skip your question because it is firstly incomplete.

LG
Member 11382784 20-Jan-15 2:52am
   
got it sir thank you......

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

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 :
protected void Page_Load(object sender, EventArgs e)
{


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

}
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100