469,646 Members | 1,151 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,646 developers. It's quick & easy.

Multiple select in a asp.net datagrid

I'm trying to create a asp.net webform with a datagrid which has been
filled with data from a database. The datagrid is filled allright but
I would like to add a checkbox at every row which the use can click to
select one or many of the rows in the datagrid once a button is
clicked. The problem is that the code behind does not recognise if the
checkbox has been check or not.

Does anyone knows how to do this?
/erik

The html code looks like this:

<asp:DataGrid id="dgListAllOrders" runat="server"
AutoGenerateColumns="False" Font-Names="Arial" CellPadding="0"
BorderWidth="1px" Font-Size="X-Small" DataKeyField="JobID">
<AlternatingItemStyle BackColor="WhiteSmoke"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" Wrap="False"
BackColor="Gainsboro"></HeaderStyle>
<Columns><asp:BoundColumn DataField="JobID" HeaderText="JobbID">
<HeaderStyle Width="50px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="chkJob" runat="server"
Checked="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

The code behind looks like this:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim dgi As DataGridItem
Dim cb As CheckBox
Dim i As Integer = 0
Dim p As Integer

For Each dgi In dgListAllOrders.Items
cb = CType(dgi.Cells(6).Controls(1), CheckBox)
If cb.Checked Then
p = CType(dgListAllOrders.DataKeys(i), Integer)
End If
i += 1
Next

End Sub
Jul 21 '05 #1
0 3371

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Billy Jacobs | last post: by
1 post views Thread by Bob Loveshade | last post: by
1 post views Thread by Eddy Balan | last post: by
8 posts views Thread by Jason L James | last post: by
reply views Thread by rn5a | last post: by
2 posts views Thread by Andy Baker | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.