I am attempting to figure out how to use a datagrid with checkboxes. I found some information for using an item template and the FindControl method. I am using Dreamweaver to program so I'm sure I'm not getting all the bells and whistles that VB.NET has to offer. I'm stumped because my code looks like so much that I have found on the web. I am getting this message when I click the submit button:
System.NullReferenceException: Object reference not set to an instance of an object.
Any advice will be unbelievably appreciated. ( put a space after the colon between ASP and DATAGRID to take out the face)
Thank you
Here's my script code:
<script language="vb" runat="server">
sub check_clicked(byVal sender as object, byVal e as eventArgs)
Dim dgItem as DataGridItem
Dim strSelected as String
Dim ckSelected as System.Web.UI.WebControls.CheckBox
For Each dgItem in dgsvcPacks.Items
ckSelected = dgsvcPacks.FindControl("ckUpdate")
if ckSelected.Checked then
strSelected = CType(dgsvcPacks.FindControl("name"),Label).Text
strSelected = strselected & "<br>"
end if
next
label1.Text = strSelected
end sub
</script>
Here's my datagrid code:
<form runat="server">
<asp: DataGrid id="dgsvcPacks" runat="server"
AutoGenerateColumns="false"
Font-Name="Vernada" Width="75%"
HorizontalAlign="Center">
<headerstyle BackColor="#21609b" ForeColor="#FFFFFF" Font-Bold="true"/>
<columns>
<asp:BoundColumn DataField="name" HeaderText="Module"/>
<asp:BoundColumn DataField="update" HeaderText="Update No" />
<asp:BoundColumn DataField="file" HeaderText="Update File Name"/>
<asp:TemplateColumn HeaderText="ckbox">
<ItemTemplate>
<asp:CheckBox ID="ckUpdate" runat="server"/>
</ItemTemplate>
</asp:TemplateColumn>
</columns>
</asp: DataGrid>
<asp:Button OnClick="check_clicked" Text="Submit" runat="server"/>
<asp:Label ID="label1" runat="server" />
</form>