Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1133
  • Last Modified:

Datagrid in visual studio 2003, asp.net

Is there a way when a button is clicked, lets say an OK button outside of the datagrid, when clicked to loop thru the datagrid and findout which rows that have a checkbox in it to findout if that checkbox is checked or not. and then assign the remainder rows to a separate datatable to do more work on?
0
sfunderwood
Asked:
sfunderwood
  • 2
  • 2
  • 2
2 Solutions
 
Alpesh PatelCommented:
Here you need some tricky things to do

first of all run your page and go to the sourve view
find out the id generated for the checkbox in the column

suppose the id generated is like chkboxgrid_0, chkboxgrid_1 chkboxgrid_2 etc.

no go through the scenario
dim chkbox as CheckBox
for i= 0 to rows.count

chkbox= ctype(me.findcontrol("chckboxgrid_"&i),CheckBox)
access chkbox properties for your use

next
0
 
RedKelvinCommented:
Hi, you can do something like this, keep in mind that variable 'y', needs to be the index of the checkbox column.
    For x As Integer = 0 To GridView1.Rows.Count - 1
      If CType(GridView1.Rows(x).Cells(y).FindControl("MyCheckbox"), CheckBox).Checked Then
        ' copy row to datatable
      End If
    Next

Open in new window

0
 
Alpesh PatelCommented:
RedKelvin

you are perfect for sfunderwood's requirement but i thing so FindControl need ID for perticular control
so would your code works perfectly ?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sfunderwoodAuthor Commented:
RedKelvin,
What would the equivalent for a GridView in .net 1.1? Or is there anything. I even thought of using a repeater for this process.
Any more help would be greatly apprecitated.
0
 
sfunderwoodAuthor Commented:
Here is the solution that I used.
Thanks for all the help!

 Dim dEdit As DataTable = Session("Editableplayers")
        Dim cSelect As CheckBox
        Dim dgi As DataGridItem
        Dim cSerial As Object
        Dim x As Integer
        Dim y As Integer
        For Each dgi In DataGrid1.Items
            cSelect = dgi.FindControl("Selectbox")
            cSerial = dgi.ItemIndex
            x = CInt(cSerial)
            If cSelect.Checked = True Then
               dEdit.Rows(x).Delete()
            End If
        Next
          dEdit.AcceptChanges()
        Session("EditablePlayers") = dEdit.Copy
        Response.Redirect("confirmclonedplayers.aspx")
0
 
RedKelvinCommented:
nah there is no equivalent in 1.1, datagrid is the closest thing
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now