How to get a specific check box cell value in datagrid

G

gugu

Hi

I have a datagrid which has 20 rows and 20 columns, 15 of 20 columns
are checkboxs and their headertexts, datafields are dynamic. I need to
loop through the whole page to see if the specific check box cell is
checked or not. The code is as follows:

For rowindex = 0 To myDataGrid.Items.Count - 1
Dim item As DataGridItem = myDataGrid.Items.Item(rowindex)
For colindex = 0 To myDataGrid.Columns.Count - 1
Dim itemColumn As DataGridColumn =
myDataGrid.Columns.Item(colindex)
Dim cellValue As Boolean
cellValue = CBool(item.Cells(colindex).Text)
If cellValue = True Then
.......................

Because the cell is check box so "item.Cells(colindex).Text" is a
invalid format. I tried another way:

cellValue = item.Cells(colindex).FindControl(columnId).Checked

The error is "Checked is not a member of Control..."

I saw some of groupers use

((CheckBox)E.Item.FindControl("id")).Checked to get if the box is
checked.

E is variable of DataGridCommandEventArgs, but my e is a
System.Web.UI.ImageClickEventArgs, so this way doesn't apply to
mydatagrid neither.

I really feel inconvenient that in Visual Studio.NET the cell only has
Text property to get value, it should has Value property and
Value.GetType to decide which value type this cell contains such as
string, integer, boolean?


Any help will be greatly appreciated.
 
K

Ken Tucker [MVP]

Hi,

For rowindex = 0 To myDataGrid.Items.Count - 1
Dim item As DataGridItem = myDataGrid.Items.Item(rowindex)
For colindex = 0 To myDataGrid.Columns.Count - 1
cellValue = CBool(Datagrid1.Item(rowindex, colindex))
If cellValue = True Then

Ken
 
G

gugu

Thanks, Ken.

But I used Visual Studio.NET, seems it doesn't support
grid.Item(rindex,cindex) any more, the error is "Item is not a member
of System...Datagrid", it only has grid.Items(index) and this only
returns a cell not the value of this cell.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top