|
 |
aspdotnet_website_programming thread: Get values from a DataGrid
Message #1 by "Mathias P" <mathiaspatrikson@y...> on Fri, 28 Feb 2003 09:52:19
|
|
Hi,
I?ve got a datagrid to which I databind a dataset that has two columns, I
also add a checkbox column to the datagrid. At a given moment I want to
loop through the datagrid to get the value from the checkbox and the
value from one of the other columns (column name: IdTour) in the datagrid
to use those to make an insert in the DB. I?ve got the code to loop
through the datagrid and to get the values from the checkboxes, but I
don?t have the code to get the value from the other columns. Can anyone
help me out with this one?
The .ASP code for the datagrid is as follows:
<asp:datagrid id="dgPlaysOn" runat="server" Height="103px"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="IdTour"
HeaderText="IdTour"></asp:BoundColumn>
<asp:BoundColumn DataField="name" HeaderText="Plays
on:"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:CheckBox ID="chkPlaysOn"
OnCheckedChanged="GetIdTour" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></TD>
And the code in the code behind section is as follows:
Dim i As Byte 'Loop index
Dim item As DataGridItem 'used to access the individual grid items
Dim cbPlaysOn As CheckBox 'Used to acces the individual checkbox
Dim bPlaysOn As Boolean
For i = 0 To dgPlaysOn.Items.Count - 1
item = dgPlaysOn.Items(i)
cbPlaysOn = CType(item.FindControl("chkPlaysOn"), CheckBox)
bPlaysOn = cbPlaysOn.Checked
'Put code to access a specific cell in the column IdTour
'Put code to call the insert statement
Next
//Mathias P
|
|
 |