How to relate bound GridView columns to an unbound checkbox in the same row?

Discussion in 'ASP .Net' started by keithb, Apr 8, 2006.

  1. keithb

    keithb Guest

    How can I relate data in the bound columns of a GridView control to an
    unbound checkbox in a template column in the same row? The checkboxes
    indicate which rows are to
    be deleted when an update button is clicked.

    Thanks,

    Keith
     
    keithb, Apr 8, 2006
    #1
    1. Advertising

  2. keithb

    Teemu Keiski Guest

    Hi,

    depending on how youb process the rows. Assuming you loop them all through
    when update button is clicked. You could just iterate

    For Each row As GridViewRow in GridView1.Rows

    Dim cbDelete As CheckBox = DirectCast(row.FindControl("CheckBox1"),
    CheckBox)

    ' Accessing text in first Cell
    Dim strText As String = row.Cells(0).Text
    '...

    'Do update etc for the row

    Next

    E.g you can access the entire row via the GridViewRow (same principle
    applies if you do update on the row straight). If you have normal
    BoundFields, then it's probably Text you are looking from them. You could
    also use TemplateField's with Literals etc, when you could locate them with
    FindControl similarly how I've done with CB. This has the advantage, than
    chaging order of columns doesn't need changes to the code accessing the data
    8since it is order-independant when using child controls with FindControl)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke


    "keithb" <> wrote in message
    news:...
    > How can I relate data in the bound columns of a GridView control to an
    > unbound checkbox in a template column in the same row? The checkboxes
    > indicate which rows are to
    > be deleted when an update button is clicked.
    >
    > Thanks,
    >
    > Keith
    >
    >
     
    Teemu Keiski, Apr 8, 2006
    #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. Michael Tobis

    bound vs unbound functions

    Michael Tobis, Jan 29, 2005, in forum: Python
    Replies:
    4
    Views:
    962
    Terry Reedy
    Jan 30, 2005
  2. Elmo Watson
    Replies:
    0
    Views:
    2,764
    Elmo Watson
    Aug 17, 2006
  3. David C

    GridView unbound checkbox state

    David C, Mar 5, 2009, in forum: ASP .Net
    Replies:
    2
    Views:
    2,297
    David C
    Mar 5, 2009
  4. Replies:
    2
    Views:
    270
  5. Vinki

    template columns and bound columns in gridview

    Vinki, Apr 25, 2007, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    870
    Vinki
    Apr 25, 2007
Loading...

Share This Page