By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,841 Members | 854 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,841 IT Pros & Developers. It's quick & easy.

checkboxlist nested inside gridview

P: 1
I have a checkbox list nested inside a gridview.

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>
&nbsp;
<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
  1.         Protected Sub gvCountries_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvCountries.RowDataBound
  2.             If e.Row.RowType = DataControlRowType.DataRow Then
  3.                 Dim ds As SqlDataSource = CType(e.Row.FindControl("RegionsDataSource"), SqlDataSource)
  4.  
  5.                 ds.SelectParameters("regionCountry").DefaultValue = gvCountries.DataKeys(e.Row.RowIndex).Value
  6.             End If
  7.         End Sub
  8.  
Jun 23 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.