468,733 Members | 1,220 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,733 developers. It's quick & easy.

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 3294

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
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.