Adding a select column...

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Adding a select column...


    Hi folks,

    I am aiming to create a "select" column that is unbound on datagrid whose
    other columns are all data bound. The idea is to let the user select items
    to be printed etc.

    The problem I have arises when I want to find out which rows are selected.
    The following code is a tester that puts values into a string to be
    displayed, but it's representative.

    Dim chk As CheckBox

    Dim itm As DataGridItem

    Dim str As String

    For Each itm In Me.dgVialList.Items

    chk = CType(itm.Cells(0).Controls(0), CheckBox)

    If chk.Checked Then

    str += itm.Cells(1).Text & ", "

    End If

    Next

    The problem occurs at chk = CType(itm.Cells(0).Controls(0), CheckBox) where
    it says that it cannot cast the item as a checkbox. This collection is base
    0?? I have only one template control (ItemTemplate).

    Any ideas?

    Cheers...P







    Paul Mason Guest

  2. Similar Questions and Discussions

    1. Select after insert to the unique column
      On Wed, Dec 08, 2004 at 14:50:04 +0100, Julian Legeny <legeny@softhome.net> wrote: Depending on what you really want to do, you could do each...
    2. Select a COLUMN in a datagrid?
      Hi, Can anyone suggest how to select or hilight a column in a Windows Forms datagrid, as visual feedback for an edit/copy command? I've tried...
    3. Getting column name in Select statement
      How can I use the column_name provided from information_schema.columns in a Select statement that is used for extracting certain columns from a...
    4. Button Select Column
      I put a select button in a datagrid, select a row works fine. Now hold down the shift key and select a second row, get jscript error. Is there...
    5. Select MAX based on partial column value?
      I need to get the max # from the following row values based on a portion of the data: abcXXX01 abcXXX02 defXXX03 abcXXX04 abcYYY01 defYYY02...
  3. #2

    Default Re: Adding a select column...


    Many apologies folks...I needed to refer to itm.Cells(0).Controls(1). I'm
    not sure why this should be so, but I've got it working now.

    Cheers...P


    "Paul Mason" <p.mason.2@bham.ac.uk> wrote in message
    news:%23wz$ocjrFHA.2996@tk2msftngp13.phx.gbl...
    >
    > Hi folks,
    >
    > I am aiming to create a "select" column that is unbound on datagrid whose
    > other columns are all data bound. The idea is to let the user select
    > items to be printed etc.
    >
    > The problem I have arises when I want to find out which rows are selected.
    > The following code is a tester that puts values into a string to be
    > displayed, but it's representative.
    >
    > Dim chk As CheckBox
    >
    > Dim itm As DataGridItem
    >
    > Dim str As String
    >
    > For Each itm In Me.dgVialList.Items
    >
    > chk = CType(itm.Cells(0).Controls(0), CheckBox)
    >
    > If chk.Checked Then
    >
    > str += itm.Cells(1).Text & ", "
    >
    > End If
    >
    > Next
    >
    > The problem occurs at chk = CType(itm.Cells(0).Controls(0), CheckBox)
    > where it says that it cannot cast the item as a checkbox. This collection
    > is base 0?? I have only one template control (ItemTemplate).
    >
    > Any ideas?
    >
    > Cheers...P
    >
    >
    >
    >
    >
    >
    >

    Paul Mason Guest

  4. #3

    Default Re: Adding a select column...

    Hi Paul,

    Actually, the better way is:



    chk = CType(itm.FindControl(checkbox_ID), CheckBox)



    So you don't need to worry about it's in Controls(0) or Controls(1).



    HTH





    "Paul Mason" <p.mason.2@bham.ac.uk> wrote in message
    news:efgoYpjrFHA.1256@TK2MSFTNGP09.phx.gbl...
    >
    > Many apologies folks...I needed to refer to itm.Cells(0).Controls(1). I'm
    > not sure why this should be so, but I've got it working now.
    >
    > Cheers...P
    >
    >
    > "Paul Mason" <p.mason.2@bham.ac.uk> wrote in message
    > news:%23wz$ocjrFHA.2996@tk2msftngp13.phx.gbl...
    > >
    > > Hi folks,
    > >
    > > I am aiming to create a "select" column that is unbound on datagrid
    whose
    > > other columns are all data bound. The idea is to let the user select
    > > items to be printed etc.
    > >
    > > The problem I have arises when I want to find out which rows are
    selected.
    > > The following code is a tester that puts values into a string to be
    > > displayed, but it's representative.
    > >
    > > Dim chk As CheckBox
    > >
    > > Dim itm As DataGridItem
    > >
    > > Dim str As String
    > >
    > > For Each itm In Me.dgVialList.Items
    > >
    > > chk = CType(itm.Cells(0).Controls(0), CheckBox)
    > >
    > > If chk.Checked Then
    > >
    > > str += itm.Cells(1).Text & ", "
    > >
    > > End If
    > >
    > > Next
    > >
    > > The problem occurs at chk = CType(itm.Cells(0).Controls(0), CheckBox)
    > > where it says that it cannot cast the item as a checkbox. This
    collection
    > > is base 0?? I have only one template control (ItemTemplate).
    > >
    > > Any ideas?
    > >
    > > Cheers...P
    > >
    > >
    > >
    > >
    > >
    > >
    > >
    >
    >

    Elton Wang Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139