Forum Discussion
TonyWONG1234
Nov 23, 2023Copper Contributor
asp.net loop checkboxes in gridview with DocumentFormat.OpenXml.Wordprocessing
it is ok to run this code to loop checked rows
dim abc as checkbox = row.cells(1).findcontrol("Cb")
but once add import DocumentFormat.OpenXml.Wordprocessing
findcontrol failed
function findcontrol is changed to UI.findcontrol
how can i fix it? thank you very much
1 Reply
- PasildaDataCopper Contributor
It looks like you're trying to find a System.Web.UI.WebControls.CheckBox within a cell, but importing the DocumentFormat.OpenXml.Wordprocessing namespace makes the CheckBox class ambiguous (there is a CheckBox class in both System.Web.UI.WebControls and DocumentFormat.OpenXml.Wordprocessing).
To get the checkbox from the cell, try using the fully qualifyed namespace. Also, I'd recommend a ctype and a null/nothing check:
dim abc as System.Web.UI.WebControls.CheckBox = CType(row.cells(1).findcontrol("Cb"), System.Web.UI.WebControls.CheckBox) If abc IsNot Nothing Then 'do something here... End If