i am trying to select multiple rows from a gridview using a checkbox in a template column. The gridview is bound to an Entity Collection (of QuestionGroupCollection in my case) in t he codebehind (not using a LLBLGenProdDatadsource, but just in the codebehind since i need some complex filtyering to happen first).
<asp:GridView ID="GridView_Results" runat="server" DataKeyNames="Id"
AutoGenerateColumns="False">
<Columns>
<asp:TemplateField>
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle BackColor="Gainsboro"/>
<ItemTemplate>
<asp:CheckBox runat="server" ID="CheckBox_SelectQuestionGroup" Text="Select" />
<asp:Label runat="server" ID="QuestionGroupName" Text='<%# Bind("Name") %>'></asp:Label>
<br />
<asp:GridView runat="server" ID="GridView_QuestionDetail" DataSource='<%# Eval("Question") %>'></asp:GridView>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Name" HeaderText="Question Group" SortExpression="Name" />
</Columns>
</asp:GridView>
<asp:Button ID="Button_UseSelectedGroups" runat="server" Text="Use Selected Groups" />
when the button is pressed i want to find the selected rows and save those entities into a new collection of selected entities:
Protected Sub Button_UseSelectedGroups_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button_UseSelectedGroups.Click
' get the groups selected and add them top the collection we will use
For Each row As GridViewRow In GridView_Results.Rows
If Not row.DataItem Is Nothing Then
Dim qg As QuestionGroupEntity = CType(row.DataItem, QuestionGroupEntity)
Dim cb As CheckBox = CType(FindControlRecursive(row, "CheckBox_SelectQuestionGroup"), CheckBox)
If cb.Checked Then
SelectedQuestionGroups.Add(qg)
End If
End If
Next
End Sub
the prblem is that the row.DataItem is always null (Nothing).
How do I get at the Entity (QuestionGroupEntity) from a row in a gridview bound to an EntityCollection (QuestionGroupCollection). Wheni step through the process and get to the button clicked event, i can't find the data items at all in the gridview.