Subscribe to Subscribers

Forums » .NET » ASP.NET »

Refresh only Check Box in GridView


Posted Date: 25 Dec 2011      Posted By:: Madhu Babu     Member Level: Bronze    Member Rank: 3076     Points: 5   Responses: 2



I have a problem in my project. I have Check Box and TextBox in one column in my GrieView. When I check the check box in my GridView I need to make visible true for TextBox. But when I check my check box, full page is refreshing. My code is as follows...


<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" Height="90px" PageSize="5" Width="909px" onrowdatabound="GridView1_RowDataBound">

<asp:TemplateField HeaderText="Is Default">
<ItemTemplate>

<asp:UpdatePanel EnableViewState="true" ID="up2" runat="server">
<Triggers>
<asp:AsyncPostBackTrigger controlid="chkDefault" eventname="CheckedChanged" />
</Triggers>
<ContentTemplate>
<asp:CheckBox ID="chkDefault" runat="server" AutoPostBack="true" OnCheckedChanged ="chkDefault_CheckedChanged" />

<asp:TextBox ID="txtDefault" runat="server" Width="120" Height="25" Visible="false"></asp:TextBox >
</ContentTemplate>
</asp:UpdatePanel>
</ItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>



protected void chkDefault_CheckedChanged(object sender, EventArgs e)
{
string str;
CheckBox chk = (CheckBox)sender;

chk.AutoPostBack = true ;
foreach (GridViewRow gvrow in GridView1.Rows)
{
bool result = ((CheckBox)gvrow.FindControl("chkDefault")).Checked;

TextBox txt = (TextBox)gvrow.Cells[4].FindControl("txtDefault");

if (result == true)
{
txt.Visible = true;
txt.Focus();
str = txt.Text;
}
else if (result == false)
{
txt.Visible = false;
str = null;
}
}

}




Responses

#648392    Author: Kushal Zamkade      Member Level: Gold      Member Rank: 157     Date: 25/Dec/2011   Rating: 2 out of 52 out of 5     Points: 4

Hi,
Hide the AutoPostback =true , so that the page will not refresh when check box is clicked.



protected void chkDefault_CheckedChanged(object sender, EventArgs e)
{
string str;
CheckBox chk = (CheckBox)sender;

//chk.AutoPostBack = true ;

foreach (GridViewRow gvrow in GridView1.Rows)
{
bool result = ((CheckBox)gvrow.FindControl("chkDefault")).Checked;

TextBox txt = (TextBox)gvrow.Cells[4].FindControl("txtDefault");

if (result == true)
{
txt.Visible = true;
txt.Focus();
str = txt.Text;
}
else if (result == false)
{
txt.Visible = false;
str = null;
}
}

}



With Regards
Kushal


 
#648425    Author: SonyMadhu      Member Level: Gold      Member Rank: 45     Date: 26/Dec/2011   Rating: 2 out of 52 out of 5     Points: 2

Hi Madhu,

To refresh only checkboxes,

foreach (GridDataItem dataItem in GridView1.MasterTableView.Items)
{
(dataItem.FindControl("chkDefault") as CheckBox).Checked = false;
}



Hope this will help you.

Regards,
Madhu
Be so hapy wen others look at you,they become hapy too


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Next : Timer Control in asp.net
Previous : Help iam getting these error how can i remove error frm my app code
Return to Discussion Forum
Post New Message
Category:

Related Messages

Active Members
TodayLast 7 Daysmore...

Awards & Gifts
Talk to Webmaster Tony John
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
2005 - 2013 All Rights Reserved.
.NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
Articles, tutorials and all other content offered here is for educational purpose only.
We are not associated with Microsoft or its partners.