Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Checkbox in Datagrid

xianxianxianxian Posts: 5Member
Hi,

i have a column in my Datagrid that contains Checkboxes..
i need the user to select the Checkbox then store the id value of that row, into an ArrayList. i have done that & it works.

The problem is, when user deselects a Checkbox, how do i remove the id of that row from the ArrayList?

thanks in advance,
xianxian

Comments

  • xianxianxianxian Posts: 5Member
    Hi,
    i finally had it working :-


    Protected Sub RowChanged(ByVal sender As System.Object, ByVal e As
    System.EventArgs)
    Dim a As New ArrayList
    If Not Session("SelectResults") Is Nothing Then
    a = CType(Session("SelectResults"), ArrayList)
    End If

    Dim dgItem As DataGridItem = CType(CType(sender,
    Control).NamingContainer, DataGridItem)
    Dim rec As Integer = CInt(dgItem.Cells(9).Text)

    If Not a.Contains(rec) Then
    a.Add(rec)
    Else
    Dim chkSel As CheckBox = CType(dgItem.Cells(0).Controls(1),
    CheckBox)
    If chkSel.Checked = False Then
    a.Remove(rec)
    End If
    End If

    Session("SelectResults") = a
    End Sub


    *PS: "rec" is a record number, just a unique item for every Checkbox in
    my Datagrid.
    Note that I have to first check whether the item is in my Arraylist,
    before i check for Checked=False. If i do it the other way round, it
    would not work.


    in HTML, just add OnCheckedChanged="RowChanged" :-







    ...


    This is just my own example, the reference is at "http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchTopQuestionsAboutASPNETDataGridServerControl.asp"
    titled "Checking for Changed items" in the section "Editing Multiple Rows At Once"
Sign In or Register to comment.