Subscribe to Subscribers

Forums » .NET » .NET »

DataGridView-Checkbox


Posted Date: 23 Nov 2009      Posted By:: shincy     Member Level: Silver    Member Rank: 1362     Points: 1   Responses: 3





I want to create events in checkbox which is inside a DataGridview in window
Application





Responses

#446017    Author: Asheej T K        Member Level: Diamond      Member Rank: 2     Date: 23/Nov/2009   Rating: 3 out of 53 out of 53 out of 5     Points: 3

Since you have multiple check boxes that may have been modified, you have to iterate through all the entries in the grid. The following sample starts with a datagrid with one template column containing a checkbox control.
It creates an array with four entries and binds to it to show four empty check boxes. Whichever check boxes you select, clicking the button shows the results.

In actual usage, you will need to have one of your columns be a unique identifier so that you can update the correct data in your database.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then
Dim MyList As New ArrayList
Dim i As Int32

For i = 0 To 3
MyList.Add(i)
Next
DataGrid1.DataSource = MyList
DataGrid1.DataBind()
Else
Dim i As Int32
For i = 0 To DataGrid1.Items.Count - 1
Dim ck As CheckBox
ck = DataGrid1.Items(i).Cells(0).FindControl("CheckBox1 ")
Response.Write(ck.Checked & "<br>")
'do databse code here
Next
End If
End Sub



---
I hope this helps.


Regards,
Asheej T K
Microsoft MVP[ASP.NET/IIS]
DotNetSpider MVM

Dotnet Galaxy


 
#446020    Author: Nagarajan      Member Level: Gold      Member Rank: 309     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

Hi shincy..

you have to set the column type as Check box in Grid View

For Example,,

1. Get the Grid View From tool bar
2. Click on column Option.
3. Then You may give the Column type like Text box, Check box, Combo box

Regards,
NAGARAJAN.R
There is nothing called Luck.. For those who deserve it...


 
#446106    Author: Narendra Reddy vajrala      Member Level: Gold      Member Rank: 163     Date: 23/Nov/2009   Rating: 2 out of 52 out of 5     Points: 2

you can try like this


private void dataGridView1_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
CheckBox ck = e.Control as CheckBox;
if (ck != null)
{
ck.CheckedChanged += new EventHandler(ck_CheckedChanged);
}
}



void ck_CheckedChanged(object sender, EventArgs e)
{
throw new NotImplementedException();
}


--Naren
Be Good and Do Good





 
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 : File Copying
Previous : Static constructor
Return to Discussion Forum
Post New Message
Category:

Related Messages

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.