The gridview pulls its data from an objectdatasource and lists countries. The nested checkbox list is databound to another object datasource and lists the regions for each country. The checkboxlist has autopostback set to true and I want to perform an action based on whether or not each checkbox is selected. I am having trouble retrieving the nested checkboxlist to access the selected values.
[HTML] <asp:SqlDataSource ID="CountriesDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:JustCivilsConnection %>"
SelectCommand="SELECT [countryID], [countryName] FROM [tblCountries] ORDER BY [countryName]">
</asp:SqlDataSource>
<div>
<asp:GridView ID="gvCountries" runat="server" AutoGenerateColumns="False" DataKeyNames="countryID"
DataSourceID="CountriesDataSource" CellPadding="2" GridLines="None">
<Columns>
<asp:BoundField DataField="countryName" HeaderText="Country" SortExpression="countryName" >
<ItemStyle Font-Bold="True" Font-Size="Medium" />
</asp:BoundField>
<asp:TemplateField HeaderText="Regions">
<ItemTemplate>
<asp:SqlDataSource ID="RegionsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:JustCivilsConnection %>"
SelectCommand="SELECT [regionID], [regionName] FROM [tblRegion] WHERE ([regionCountry] = @regionCountry) ORDER BY [regionName]">
<SelectParameters>
<asp:Parameter Name="regionCountry" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
<asp:CheckBoxList ID="cblRegions" runat="server" AutoPostBack="True" DataSourceID="RegionsDataSource"
DataTextField="regionName" DataValueField="regionID" OnSelectedIndexChanged="cblRegions_SelectedIndexCh anged">
</asp:CheckBoxList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Left" VerticalAlign="Top" />
<HeaderStyle HorizontalAlign="Left" />
</asp:GridView>
</div>[/HTML]
Expand|Select|Wrap|Line Numbers
- Protected Sub gvCountries_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCountries.RowDataBound
- If e.Row.RowType = DataControlRowType.DataRow Then
- Dim ds As SqlDataSource = CType(e.Row.FindControl("RegionsDataSource"), SqlDataSource)
- ds.SelectParameters("regionCountry").DefaultValue = gvCountries.DataKeys(e.Row.RowIndex).Value
- End If
- End Sub