Error Checkbox State inside Datagrid

Discussion in 'ASP .Net Datagrid Control' started by Martin, Mar 3, 2005.

  1. Martin

    Martin Guest

    Hello,

    I have one checkbox inside a datagrid and I want to read the state of the
    checkbox
    after submit. The checkbox is autopostback = false the only submit comes
    from the
    button.


    Let me explain, this code is ok if you only have one datagrid and set in
    design time
    the bound columns

    ' This code is OK.
    <asp:TemplateColumn HeaderStyle-HorizontalAlign=Center HeaderText="X">
    <ItemTemplate>
    <asp:Checkbox ID="chkSelection" Runat=server />
    </ItemTemplate>
    </asp:TemplateColumn>


    <asp:Button id="cmdSubmit" runat="server" Text="Next"
    OnClick="fillColSelectedChecks"></asp:Button>

    Public Sub fillColSelectedGames(ByVal sender As System.Object, ByVal e As
    System.EventArgs)
    Dim dgItem As DataGridItem
    Dim chkSelected As CheckBox

    For Each dgItem In dg_checkBox.Items
    chkSelected = myDataGridItem.FindControl("chkSelection") ...
    Next
    end Function


    But when I run this code I lose completely the items
    because dg_checkBox.Items.count = 0
    I'm forzed to have my dynamically created datagrid with bound columns :(

    Private Function buildDataGrid(dim dg as datagrid) as datagrid
    Try
    Dim col As BoundColumn

    Dim tm As TemplateColumn = New TemplateColumn
    Dim mycol As ColumnTemplate = New ColumnTemplate
    tm.HeaderText = ""
    tm.ItemTemplate = mycol
    dg.Columns.AddAt(1, tm)

    col = New BoundColumn
    col.HeaderText = "Description"
    col.DataField = "Description"
    col.Visible = True
    dg.Columns.Add(col)

    return dg
    End Sub

    Public Class ColumnTemplate
    Implements ITemplate

    Public Sub InstantiateIn(ByVal container As Control) Implements
    ITemplate.InstantiateIn
    Dim myLabel As Label = New Label
    myLabel.Text = ""
    Dim mycheckbox As CheckBox = New CheckBox
    container.Controls.Add(myLabel)
    container.Controls.Add(mycheckbox)
    End Sub

    End Class


    Any Idea is appreciate. Thanks
    Martin, Mar 3, 2005
    #1
    1. Advertising

  2. Martin

    Martin Guest

    The answer is:
    Is not posible to read the data in this way

    For Each dgItem In dg_checkBox.Items
    chkSelected = myDataGridItem.FindControl("chkSelection") ...
    Next

    when you are writing hard coded ColumnTemplates programmatically into the
    page.

    The solution is:
    Read the submit info with request.form

    Thank u anyway.
    Martin, Mar 10, 2005
    #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. mehul
    Replies:
    0
    Views:
    756
    mehul
    May 3, 2004
  2. Mark
    Replies:
    3
    Views:
    1,390
  3. kleykir
    Replies:
    0
    Views:
    426
    kleykir
    Aug 18, 2005
  4. =?Utf-8?B?RG90TmV0RGV2?=

    DataGrid and embeded Checkbox..How to find if checkbox clicked

    =?Utf-8?B?RG90TmV0RGV2?=, Oct 6, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    782
    David Wier
    Oct 6, 2006
  5. Joey Pang
    Replies:
    4
    Views:
    493
    Joey Pang
    Jun 13, 2005
Loading...

Share This Page