Retrieving the Value of a checkbox Webserver Control From a Datagrid

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 17beach
    New Member
    • Sep 2006
    • 8

    Retrieving the Value of a checkbox Webserver Control From a Datagrid

    I am using a checkbox webserver controls in template column of a datagrid webserver Control

    I am trying to iterate through the datagid and process rows based on the whether the checkbox for the row is checked or not. However when I attempt to retrieve the selection the checkbox.checke d state is false for all rows regardless of whehter the checkbox was checked or not


    Here is what I have any assistance appreciated


    <Itemtemplate >
    <asp:Checkbox id =”checkbox1” runat= “server” autopostback= “true”></asp:Checkbox>
    </Item template>

    Dim ChBox As CheckBox
    intCount As integer



    For intCount to Datagrid1.Items .count -1
    ChBox = Datagrid1.Items (intCount).Cell s(0).Controls(1 )

    If chBox.checked
    ‘Do some stuff

    Else
    ‘Do something else

    Next
  • dip_developer
    Recognized Expert Contributor
    • Aug 2006
    • 648

    #2
    Originally posted by 17beach
    I am using a checkbox webserver controls in template column of a datagrid webserver Control

    I am trying to iterate through the datagid and process rows based on the whether the checkbox for the row is checked or not. However when I attempt to retrieve the selection the checkbox.checke d state is false for all rows regardless of whehter the checkbox was checked or not


    Here is what I have any assistance appreciated


    <Itemtemplate >
    <asp:Checkbox id =”checkbox1” runat= “server” autopostback= “true”></asp:Checkbox>
    </Item template>

    Dim ChBox As CheckBox
    intCount As integer



    For intCount to Datagrid1.Items .count -1
    ChBox = Datagrid1.Items (intCount).Cell s(0).Controls(1 )

    If chBox.checked
    ‘Do some stuff

    Else
    ‘Do something else

    Next

    [CODE=vbnet]
    Dim chkBox As CheckBox
    ' Go through each row and find a check box
    For Each i As DataGridItem In Datagrid1.Items
    chkBox = CType(i.FindCon trol("checkbox1 "), CheckBox)

    If chkBox .Checked Then
    ''Do some stuff
    Else
    ''Do something else
    End If
    Next
    [/CODE]

    Comment

    Working...