aspx thread: AW: Re: Referencing an asp:Checkbox contorl to a row (item) in a datagrid
Hi,
I could not catch the "oncheckedchanged" but it might be useful to have only
one roundtrip. Try the following:
<asp:datagrid id="dgArticleSelect" runat="server" Height="100px"
Width="177px" AutoGenerateColumns="False" DataKeyField="ID"
OnDeleteCommand="ArticleDelete" OnUpdateCommand="ArticleUpdate" OnCancelCommand="ArticleCancel"
OnEditCommand="ArticleEdit" ShowFooter="False">
<Columns>
<asp:TemplateColumn HeaderText="SELECT">
<ItemTemplate>
<asp:CheckBox id="cbSelectBox" runat="server" Checked="False"
AutoPostBack="False"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
.
.
.
vb-file:
Private Sub btnArticleSubmitSelection_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles btnArticleSubmitSelection.Click
Dim i As Integer
Dim cbSelection As CheckBox
sqlConn.Open()
For i = 0 To (dgArticleSelect.Items.Count - 1)
cbSelection
CType(dgArticleSelect.Items(i).Cells(0).Controls(1), CheckBox)
If cbSelection.Checked = True Then
Dim cmd As New SqlCommand("insertxxx2yyy", sqlConn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@txtID",
SqlDbType.NVarChar, 50))
cmd.Parameters.Add(New SqlParameter("@txtaaa",
SqlDbType.NVarChar, 50))
cmd.Parameters.Add(New SqlParameter("@txtbbb",
SqlDbType.NVarChar, 50))
cmd.Parameters.Add(New SqlParameter("@txtccc",
SqlDbType.NVarChar, 50))
cmd.Parameters("@txtId").Value
dgArticleSelect.Items(i).Cells(1).Text()
cmd.Parameters("@txtaaa").Value
dgArticleSelect.Items(i).Cells(2).Text()
cmd.Parameters("@txtbbb").Value
dgArticleSelect.Items(i).Cells(3).Text()
cmd.Parameters("@txtccc").Value
dgArticleSelect.Items(i).Cells(4).Text()
cmd.ExecuteNonQuery()
cmd.Dispose()
End If
Next
sqlConn.Close()
dgArticleSelect.EditItemIndex = -1
dgArticleSelectDatabind()
End Sub
Cheers Oli
-----Ursprüngliche Nachricht-----
Von: Lou Feicht [mailto:lfeicht@f...]
Gesendet: 04 December 2001 00:34
An: ASP+
Betreff: [aspx] Re: Referencing an asp:Checkbox contorl to a row (item)
in a datagrid
Did you find a solution to this?
I'm stuck on the same problem with checkboxes
> Dear Experts,
>
> I use a DataGrid to diplay the contents of a database table on a .aspx
> site. I added a column, bearing a checkbox, to select items out of the
> DataGrid.
>
> I tried to use an event handler to react to every click at the
checkboxes.
> When an item (row of the DataGird) is selected / deselected, the
> coresponding item should be stored /deleted immediately in a separate
> database.
>
> The problem is, that I am not able to get a reference from the checkbox
to
> the corresponding datarow of the datagrid, when the "oncheckedchanged"
> event of the checkbox is fired. My first idea was to use the ID of the
> checkboxes, but the checkboxes in the different rows of the datagrid
have
> all the same ID, as defined at the ItemTemplate within
the "<ASP:DataGrid"
> tag.
>
> Is there any other (hopefully comfortable) way to reference to a row
> within a datagrid, or an other event (maybe a helpful DataGrid event)? I
> already tried the OnItemCommand event of the datagrid, but this seems to
> work only with command buttons and not with checkboxes.
>
> Thanks in advance for your helpful advices.
>
> Regards,
>
> Sascha
---
VBug Winter Conference 2001
Open Forum: Dan Appleman will be hosting an open
forum at The .NET Developer's Conference on
29th November 2001. The session will give
developers the chance to discuss and question
Dan on his experience with the .NET environment.
Dan has been programming Visual Basic since the
alpha version 1.0. And with over 10 years
Visual Basic experience is well qualified to
help you on your road to being a .NET Guru.
http://www.vbug.co.uk/redirect.asp?url=39&id=17
---
You are currently subscribed to
aspx as: saturnius@g...
$subst('Email.Unsub')
--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net