Results 1 to 6 of 6

Thread: [02/03] ASP.Net - editing datagrid checkbox column

  1. #1

    Thread Starter
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    [02/03] ASP.Net - editing datagrid checkbox column

    Okay,

    I have a datagrid which has a checkbox on each row which was done using this code:
    Code:
    <asp:TemplateColumn HeaderText="Combine">
      <ItemTemplate>
        <asp:CheckBox id="chkCombine" tabIndex="12" Runat="server"></asp:CheckBox>
      </ItemTemplate>
    </asp:TemplateColumn>
    I can read the checked value without problem using:
    Code:
    Dim chkCombine As ComboBox
    chkCombine = value.FindControl("chkCombine")
    However, the troubles come when I attempt to CHANGE that checked value as the datagrid is bound to a generated datatable, NOT to a dataset

    Any ideas on how I can programmatically edit the checkbox on each row would be most welcome.

    Valleys
    Life is one big rock tune

  2. #2
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: [02/03] ASP.Net - editing datagrid checkbox column

    Why can't you just change the value in the underlying DataTable?
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

  3. #3

    Thread Starter
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: [02/03] ASP.Net - editing datagrid checkbox column

    Quote Originally Posted by SeanGrebey
    Why can't you just change the value in the underlying DataTable?
    I don't know how to identify it as a checkbox column, it just changes it to a True/False column. Really annoying.
    Life is one big rock tune

  4. #4

    Thread Starter
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: [02/03] ASP.Net - editing datagrid checkbox column

    The current code:
    Code:
    Dim dr As DataRow
    Dim dt As New DataTable
    
    dt.Columns.Add(New DataColumn("Relation"))
    dt.Columns.Add(New DataColumn("FieldName"))
    dt.Columns.Add(New DataColumn("Operator"))
    dt.Columns.Add(New DataColumn("Value"))
    
    dr(0) = "String1"
    dr(1) = "String2"
    dr(2) = "String3"
    dr(3) = This column I want to be a checkbox column
    Life is one big rock tune

  5. #5

    Thread Starter
    Fanatic Member Valleysboy1978's Avatar
    Join Date
    Nov 2004
    Location
    Planet Xeoroaniar CC Posts:1,928,453,459,361
    Posts
    770

    Re: [02/03] ASP.Net - editing datagrid checkbox column

    Sean, using your from suggestion here:http://www.vbforums.com/showthread.php?t=401090. Will let you know if it works
    Life is one big rock tune

  6. #6
    Frenzied Member
    Join Date
    Mar 2004
    Location
    Orlando, FL
    Posts
    1,618

    Re: [02/03] ASP.Net - editing datagrid checkbox column

    Yeah, you can bind the data from your datatable to the CheckBox manually. The datagrid has an ItemDataBound event. Inside it you can do something along the lines of:

    VB Code:
    1. Private Sub dgMyGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgMyGrid.ItemDataBound
    2.  
    3.             Dim ckbMyCheckBox As Web.UI.WebControls.CheckBox = e.Item.FindControl("ckbMyCheckBox")
    4.  
    5.             Dim intRowNumber As Int32 = (dgMyGrid.CurrentPageIndex * dgMyGrid.PageSize) + e.Item.ItemIndex
    6.  
    7.  
    8.             ' Populate the row controls from Data Table
    9.             ckbPending.Checked = CBool(MyDataTable.Rows(intRowNumber).Item(3))
    10.  
    11. End Sub
    Sean

    Some days when I think about the next 30 years or so of my life I am going to spend writing code, I happily contemplate stepping off a curb in front of a fast moving bus.

Posting Permissions

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



Click Here to Expand Forum to Full Width