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


Top 5 Contributors of the Month
david stephan

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
Hi..

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..

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

hi,
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.....

Thanks
Mahesh



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
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

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