K
KatB
Hi, here is my HTML for the datagrid:
<asp:datagrid id="dgToppings" style="Z-INDEX: 107; LEFT: 144px;
POSITION: absolute; TOP: 517px" tabIndex="4" runat="server"
Font-Names="Verdana" Font-Size="11pt" Height="40px" Width="336px"
GridLines="None" ShowHeader="False" BorderColor="Red"
AuogenerateColumns="False" CellSpacing="1"
CellPadding="0" BorderWidth="0px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemDesc">
</asp:BoundColumn>
<asp:BoundColumn DataField="ItemPrice"
DataFormatString="{0:C}"></asp:BoundColumn>
</Columns>
</asp:datagrid>
And here is my code (I'm trying to retrieve values in the row where the
chkSelected checkbox = true). On the
Dim dgItem As DataGridItem
Dim chkSelected As WebControls.CheckBox
Dim sTopping As String
Dim sToppingPrice As String
For Each dgItem In dgToppings.Items
Dim chkBox As CheckBox = CType(dgItem.FindControl("chkSelected"),
CheckBox)
If Not (chkBox Is Nothing) And chkBox.Checked Then
sTopping = CType(dgItem.FindControl("ItemDesc"), TextBox).Text
sToppingPrice = CType(dgItem.FindControl("ItemPrice"),
TextBox).Text
End If
Next
It find the checked box correctly but gets a "null reference" on
"sTopping = CType" line.
Clues anyone? I've tried several things I've seen out there...but no
luck.
Thanks, Kat
<asp:datagrid id="dgToppings" style="Z-INDEX: 107; LEFT: 144px;
POSITION: absolute; TOP: 517px" tabIndex="4" runat="server"
Font-Names="Verdana" Font-Size="11pt" Height="40px" Width="336px"
GridLines="None" ShowHeader="False" BorderColor="Red"
AuogenerateColumns="False" CellSpacing="1"
CellPadding="0" BorderWidth="0px">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID="chkSelected" runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="ItemDesc">
</asp:BoundColumn>
<asp:BoundColumn DataField="ItemPrice"
DataFormatString="{0:C}"></asp:BoundColumn>
</Columns>
</asp:datagrid>
And here is my code (I'm trying to retrieve values in the row where the
chkSelected checkbox = true). On the
Dim dgItem As DataGridItem
Dim chkSelected As WebControls.CheckBox
Dim sTopping As String
Dim sToppingPrice As String
For Each dgItem In dgToppings.Items
Dim chkBox As CheckBox = CType(dgItem.FindControl("chkSelected"),
CheckBox)
If Not (chkBox Is Nothing) And chkBox.Checked Then
sTopping = CType(dgItem.FindControl("ItemDesc"), TextBox).Text
sToppingPrice = CType(dgItem.FindControl("ItemPrice"),
TextBox).Text
End If
Next
It find the checked box correctly but gets a "null reference" on
"sTopping = CType" line.
Clues anyone? I've tried several things I've seen out there...but no
luck.
Thanks, Kat