Error Checkbox State inside Datagrid

M

Martin

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
 
M

Martin

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top