473,386 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 3483

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

Similar topics

0
by: rob | last post by:
Here is my scenario: One of my aspx pages has a CheckBoxList (Item1, Item2) and a GridView. Then I have a database that has the columns Item1 and Item2 (among others) with the data type bit....
3
by: I am Sam | last post by:
I keep getting the following error message when I try to iterate through a CheckBoxList control: Object reference not set to an instance of an object. Description: An unhandled exception...
0
by: Faybert | last post by:
Hello, and Thanks in advance for any light you might shed on my troubles. I'm trying to setup a series of checkboxes, or a checkboxlist to control the results that are shown on a gridview...
0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
1
by: Mike | last post by:
I have a Datalist control on my page that I have binded to a table of available categories. In the Item Template I have a CheckboxList control bound to the products available in each Category. I...
0
by: manuel.ricca | last post by:
Hello, I'm trying to create a table with 2 nested gridviews and then a DetailsView on the right. The DetailsView should show the details of the item selected in the 2nd (nested) GridView: My...
0
by: avital | last post by:
Hi, Hope someone can please help. I have a Gridview with a checkboxlist. On edititemTemplate I want the checkboxlist items to be selected as returned from the database. In the database I...
0
by: joebob8000 | last post by:
This seems like a simple task, but my 6 year old roots in classic ASP must be causing me trouble with my current problem. I am looking to provide a search for users in which they can select...
2
by: mercea | last post by:
hi all, i have a grid view and i have inserted a checboxlist template with 5checkboxes per row into the gridview. i want the user to be able to select an option (A-E) and that selected option be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.