Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Error Checkbox State inside Datagrid

Reply
Thread Tools

Error Checkbox State inside Datagrid

 
 
Martin
Guest
Posts: n/a
 
      03-03-2005
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


 
Reply With Quote
 
 
 
 
Martin
Guest
Posts: n/a
 
      03-10-2005
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
CheckBox Validation inside a Datagrid kleykir ASP .Net 0 08-18-2005 02:40 PM
Howto bind CheckBox to the datagrid/ Then update the database field when the checkbox is clicked. Joey Pang ASP .Net Datagrid Control 4 06-13-2005 02:29 AM
Assoicate a primary key with a checkbox inside a datagrid Mark ASP .Net 3 04-28-2005 02:47 AM
CheckBox template always evaluate to False even if checked in a DataGrid hosted inside a TabStrip mehul ASP .Net 0 05-03-2004 12:07 PM



Advertisments