.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

Checkbox enable and disable in gridview

Posted By: Madhu Gowda     Posted Date: May 18, 2011    Points:5   Category :ASP.Net

i am using Checkbox column in gridview...i dont know how to make check and uncheck dynamically (using c# language)..please help me

thank you in advance..

Author: Mahesh             
Posted Date: May 18, 2011     Points: 20   

u can do this in row databound event of gridview as,

Protected Sub DataGV_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles DataGV.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then '1
Dim Chk As CheckBox = e.Row.FindControl("CheckBox1?) '2
chk.checked= true ' as per u r req

Page.ClientScript.RegisterStartupScript(Me.GetType(), "MyScript", " function HighlightSelected(colorcheckboxselected, RowState) { if (colorcheckboxselected.checked) colorcheckboxselected.parentElement.parentElement.style.backgroundColor='#FFAA63'; else { if (RowState=='0') colorcheckboxselected.parentElement.parentElement.style.backgroundColor='white'; else colorcheckboxselected.parentElement.parentElement.style.backgroundColor='#D6E3F7'; } }", True) '3
Chk.Attributes.Add("onclick", "HighlightSelected(this,'" + Convert.ToString(e.Row.RowState) + "' );") '4

End If '5
End Sub

hope this helps.....


Post Reply

You must Sign In To post reply
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend