Programmatically binding datagrid

Discussion in 'ASP .Net' started by Niclas Lindblom, Apr 8, 2004.

  1. Hi,

    I have a datagrid that contains a checkbox template column. I have followed
    the sample in Q306227, but I have a problem evaluating the content of the
    datagrid columns to decide a value for the checkboxes check property.

    According to the sample I should use this statement in the BindCheckbox
    event to evaluate a column:

    Public Sub BindCheckBox(ByVal sender As Object, ByVal e As EventArgs)
    'Create a new instance of a CheckBox.
    Dim oCheckBox As CheckBox = CType(sender, CheckBox)
    Dim container As DataGridItem = CType(oCheckBox.NamingContainer,
    DataGridItem)
    'Evaluate the data from the Grid item and set the Checked property
    ' appropriatly
    If container.DataItem("contract").GetType.ToString = "System.DBNull"
    Then
    oCheckBox.Checked = False
    Else
    oCheckBox.Checked = CBool(container.DataItem("contract"))
    End If

    End Sub


    The problem here is that my project is configured to use "Option Strict" and
    does therefore not allow the statement

    If container.DataItem("contract").GetType.ToString = "System.DBNull" Then

    I tried to use Container.cells(2).text instead, but this only returns a
    empty string in all rows.

    Any suggestions on how to to do this ?

    Regards

    Niclas
     
    Niclas Lindblom, Apr 8, 2004
    #1
    1. Advertising

  2. Hi, Niclas

    Why not try
    If IsDBNull(container.DataItem("contract")) The
    oCheckBox.Checked = Fals
    Els
    oCheckBox.Checked = CBool(container.DataItem("contract")
    End I

    Bin Song, MC

    ----- Niclas Lindblom wrote: ----

    Hi

    I have a datagrid that contains a checkbox template column. I have followed
    the sample in Q306227, but I have a problem evaluating the content of the
    datagrid columns to decide a value for the checkboxes check property

    According to the sample I should use this statement in the BindCheckbox
    event to evaluate a column

    Public Sub BindCheckBox(ByVal sender As Object, ByVal e As EventArgs
    'Create a new instance of a CheckBox
    Dim oCheckBox As CheckBox = CType(sender, CheckBox
    Dim container As DataGridItem = CType(oCheckBox.NamingContainer,
    DataGridItem
    'Evaluate the data from the Grid item and set the Checked propert
    ' appropriatl
    If container.DataItem("contract").GetType.ToString = "System.DBNull"
    The
    oCheckBox.Checked = Fals
    Els
    oCheckBox.Checked = CBool(container.DataItem("contract")
    End I

    End Su


    The problem here is that my project is configured to use "Option Strict" and
    does therefore not allow the statemen

    If container.DataItem("contract").GetType.ToString = "System.DBNull" The

    I tried to use Container.cells(2).text instead, but this only returns a
    empty string in all rows

    Any suggestions on how to to do this

    Regard

    Niclas
     
    =?Utf-8?B?QmluIFNvbmcsIE1DUA==?=, Apr 8, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,536
    Jordan
    Feb 10, 2004
  2. Guest
    Replies:
    2
    Views:
    6,946
    Guest
    Jun 28, 2005
  3. Amit
    Replies:
    6
    Views:
    13,807
    Assimalyst
    Oct 24, 2006
  4. =?Utf-8?B?TWlrZSBDb2xsaW5z?=

    Binding a GridView Programmatically

    =?Utf-8?B?TWlrZSBDb2xsaW5z?=, Nov 5, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    550
    Eliyahu Goldin
    Nov 6, 2006
  5. Replies:
    2
    Views:
    863
    Kevin Grover
    Oct 20, 2006
Loading...

Share This Page