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
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