DataGrid Assistance

  • Thread starter Thread starter Bob
  • Start date Start date
B

Bob

I have a datagrid on a web form that is bound to a
SQLServer stored procedure.

I used the Item Template to add a checkbox column to my
grid.

So far so good..

Now I'm in the code behind, looping through the rows and I
can't seem to figure out C# .NET to write the statement to
chec to see if the checkbox is checked or not!

Can anyone advise???

My checkbos is in column 3. I'm able to write this code
to get the text but can't figure out how to determine if
the box is checked or not.

Debug.WriteLine(DataGrid1.Items.Cells[3].Text);


Thanks

Bob
 
The following code snippet assumes an asp:checkbox with
runat=server exists in that column. In that case, you
can use the following:


if(((CheckBox)dgAddendum.Items.Cells[3].FindControl
("myControlId")).Checked){
Response.Write(i.ToString() + " is checked");
}


Jerry Negrelli
Senior Software Engineer
Data Scientific Corporation
 
Hi Bob,

The best way to access a control inside a row in a grid is using Find()
like this:

DataGridItem.FindControl( "The_Control_ID")

then you can cast it to the expected type:

(CheckBox)DataGrid1.Items.FindControl( "The_Control_ID");


Hope this help,
 
Back
Top