|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Implicit conversion from one object to anotherI am sure there must be a way to do this but I have not found it yet. I want to be able to loop through all rows in a data grid, check the state of a checkbox column - and if it is checked for that row then perform some action. The code below will do this BUT it implicitly converts a Control to a CheckBox - which means I can only do this if I switch off Option Strict (Which I don't want to do). Any ideas how I could achieve the same with the Option Strick switched on? Dim ctlChk As CheckBox For Each Item As DataGridItem In dgMyDataGrid.Items ctlChk = Item.Cells(5).Controls(1) If ctlChk.Checked Then Do Something... End if Next -- Ben I have found a solution - by using DirectCast keyword:
ctlChk = DirectCast(Item.Cells(5).Controls(1), CheckBox) -- Show quoteHide quoteBen "Ben S" wrote: > Hello, > I am sure there must be a way to do this but I have not found it yet. > I want to be able to loop through all rows in a data grid, check the state > of a checkbox column - and if it is checked for that row then perform some > action. > The code below will do this BUT it implicitly converts a Control to a > CheckBox - which means I can only do this if I switch off Option Strict > (Which I don't want to do). > > Any ideas how I could achieve the same with the Option Strick switched on? > > Dim ctlChk As CheckBox > For Each Item As DataGridItem In dgMyDataGrid.Items > ctlChk = Item.Cells(5).Controls(1) > If ctlChk.Checked Then > Do Something... > End if > Next > > -- > Ben Add the column to your datasource as a boolean. Then bind the datasource to
the grid and make the column type a checkbox. You can then get the value of the cell as a boolean instead finding the checkbox. I have never tried this with an asp webgrid, but this is standard practice with the infragistics webgrid. This is a standard practice in .net 2.0 gridview. -- Show quoteHide quoteStaff Consultant II - Enterprise Web Services - Cardinal Solutions Group Future Business Model - National City Mortgage "Ben S" wrote: > Hello, > I am sure there must be a way to do this but I have not found it yet. > I want to be able to loop through all rows in a data grid, check the state > of a checkbox column - and if it is checked for that row then perform some > action. > The code below will do this BUT it implicitly converts a Control to a > CheckBox - which means I can only do this if I switch off Option Strict > (Which I don't want to do). > > Any ideas how I could achieve the same with the Option Strick switched on? > > Dim ctlChk As CheckBox > For Each Item As DataGridItem In dgMyDataGrid.Items > ctlChk = Item.Cells(5).Controls(1) > If ctlChk.Checked Then > Do Something... > End if > Next > > -- > Ben
Strange Error when viewing page
HtmlInputFile issue get the value of dropdownList check if image or file exists Easy way to use bound combo with foreignkey id/value on webform? Target property of ASP hyperlink? set focus List'o MyProj CSS Elements? View DataSet Relational Data how to insert text into middle of textarea |
|||||||||||||||||||||||