Handling a CheckBox in a DataGrid

liunx

Guest
Hi

I have a DataGrid which is populated by a stored proc, however I have added a non-databound CheckBox at .cell(0) of the DataGrid.

The idea is to include the databound values of the DataGrid in a search IF the non-databound CheckBox is selected.

My problem is I cannot find a way to get a handle on the CheckBox. Ideally, I would like to loop through the DataGrid and collect the 'checked' status of the CheckBox on each row of the DataGrid. :confused:

Any ideas?

Thanks.

AJNI've decided to bring the boolean value of the checkbox back from the database, to make the checkbox databound. Does anyone know how I can bind the boolean column to the checkbox in the datagrid?

Here is the dgrid:

<asp:datagrid EnableViewState="True" ID="grdRegion" Runat="server" AutoGenerateColumns="false" GridLines="None" CssClass="grdRegion" BorderWidth="0" BorderStyle="None">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="cbxRegionSelected" Runat="server">
</asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="fas_region_id" Visible="False"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="lbtnViewDetails" Runat="server">
<%# DataBinder.Eval(Container.DataItem, "name").tostring%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>

Edit: Thanks

AJNOk, so that's that done and thanks for your help so far! ;)

The solution to bind the checkbox in the datagrid is in the datagrid ItemDataBound, as follows:


If e.Item.ItemType = ListItemType.Item Then
If LCase(e.Item.Cells(0).Text) = "true" Then 'where cell(0) is a hidden databound column in the datagrid with the text value of True/False
Dim cbxRegionSelected As CheckBox = e.Item.FindControl("cbxRegionSelected")
cbxRegionSelected.Checked = True
Else
cbxRegionSelected.Checked = False
End If
ElseIf e.Item.ItemType = ListItemType.AlternatingItem Then
'
End If


Now what I need to do is capture the click event of the checkbox inside the datagrid. I can capture the other click events of the datagrid with the commandName in the itemCommand, but I cannot assign a commandName to the checkbox!!!

So, does anyone know how to capture the click event of a checkbox inside a datagrid?

Edit...

Perhaps the question should be; how can I assign a commandName to the checkbox at the ItemDataBound (or other) stage??

Thanks

AJN
 
Back
Top