471,049 Members | 1,423 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

checkboxlist nested inside gridview

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
0 3366

Post your reply

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

Similar topics

3 posts views Thread by I am Sam | last post: by
reply views Thread by hammad.awan_nospam | last post: by
reply views Thread by manuel.ricca | last post: by
reply views Thread by avital | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.