473,569 Members | 2,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Two DropDownList controls in one DataGrid cell

Hi folks,

I need to have two ddl's in one DataGrid cell. The first ddl has a list of
company names and the second has a list of contact names that work in the
company name that was selected in the first ddl.

Any replies will be greatly appreciate.

Here are 3 functions / subroutines that do the following:

1) GetCompanyNames ForThisProject
2) GetContactsFrom CompanyForThisP roject
3) ddlTo_SelectedI ndexChanged
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "Provider=Micro soft.Jet.OLEDB. 4.0;
Ole DB Services=-4; Data
Source=c:\sites \single29\gmead ows73\database\ fdmdb.mdb"
Dim queryString As String = "SELECT DISTINCT [users].[cname] FROM
[users] WHERE ([users].[project] = '" & Session("projec t") & "')"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users

Return dsCompanyNames
End Function

Function GetContactsFrom CompanyForThisP roject () As DataSet
' dsContacts.Clea r()
Dim strConnString As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\sites \single29\gmead ows73\database\ fdmdb.mdb"

Dim queryString As String
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (queryString,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName = list.SelectedIt em.Text

Dim ddlContact As DropDownList = CType(sender, DropDownList)
ddlContact.Data Source = GetContactsFrom CompanyForThisP roject ()
ddlContact.Data Bind ( )
End Sub

The first ddl is populated with company names. When it is selected the code
travels into the second function to get the contact names for the company
that was selected. The problem is that the second ddl is never populated
with the contact names.

My DataGrid html snippet is as follows:

<asp:TemplateCo lumn HeaderText="To"
SortExpression= "questionto ">
<ItemTemplate >
<%# DataBinder.Eval (Container.Data Item,
"questionto ") %>
</ItemTemplate>
<EditItemTempla te>
<asp:Label id="lblFrom" text="Company: "
runat="server" />
<br />
<asp:DropDownLi st id="ddlTo" runat="server"
DataValueField= "cname" AutoPostBack="T rue" DataSource='<%#
GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged" />
<asp:Label id="lblContact " text="Contact: "
runat="server" />
<br />
<asp:DropDownLi st id="ddlContact " runat="server"
DataValueField= "name" AutoPostBack="T rue" DataSource='<%#
GetContactsFrom CompanyForThisP roject() %>'/>
</EditItemTemplat e>
</asp:TemplateCol umn>

Apr 25 '06 #1
1 1326
Hi folks,

Solved my own problem. For anyone interested, the following snippet needs
to go inside of your OnSelectItem subroutine:

Dim list As DropDownList = CType(sender, DropDownList)
coName = list.SelectedIt em.Text

Dim cell As TableCell = CType(list.Pare nt, TableCell)
Dim item As DataGridItem = CType(cell.Pare nt, DataGridItem)
Dim ddlContact As DropDownList =
CType(item.Find Control("ddlCon tact"), DropDownList)
ddlContact.Data Source = GetContactsFrom CompanyForThisP roject ()
ddlContact.Data Bind ( )

"glenn" wrote:
Hi folks,

I need to have two ddl's in one DataGrid cell. The first ddl has a list of
company names and the second has a list of contact names that work in the
company name that was selected in the first ddl.

Any replies will be greatly appreciate.

Here are 3 functions / subroutines that do the following:

1) GetCompanyNames ForThisProject
2) GetContactsFrom CompanyForThisP roject
3) ddlTo_SelectedI ndexChanged
Function GetCompanyNames ForThisProject( ) as DataSet
dsCompanyNames. Clear()
Dim strConnString As String = "Provider=Micro soft.Jet.OLEDB. 4.0;
Ole DB Services=-4; Data
Source=c:\sites \single29\gmead ows73\database\ fdmdb.mdb"
Dim queryString As String = "SELECT DISTINCT [users].[cname] FROM
[users] WHERE ([users].[project] = '" & Session("projec t") & "')"

Dim dataAdapter As New OleDbDataAdapte r (querystring, strConnString)

dataAdapter.Fil l(dsCompanyName s, "users

Return dsCompanyNames
End Function

Function GetContactsFrom CompanyForThisP roject () As DataSet
' dsContacts.Clea r()
Dim strConnString As String =
"Provider=Micro soft.Jet.OLEDB. 4.0; Ole DB Services=-4; Data
Source=C:\sites \single29\gmead ows73\database\ fdmdb.mdb"

Dim queryString As String
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("projec t") & "'))"

Dim dataAdapter As New OleDbDataAdapte r (queryString,
strConnString)

dataAdapter.Fil l(dsContacts, "users")

Return dsContacts
End Function

Sub ddlTo_SelectedI ndexChanged(sen der As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName = list.SelectedIt em.Text

Dim ddlContact As DropDownList = CType(sender, DropDownList)
ddlContact.Data Source = GetContactsFrom CompanyForThisP roject ()
ddlContact.Data Bind ( )
End Sub

The first ddl is populated with company names. When it is selected the code
travels into the second function to get the contact names for the company
that was selected. The problem is that the second ddl is never populated
with the contact names.

My DataGrid html snippet is as follows:

<asp:TemplateCo lumn HeaderText="To"
SortExpression= "questionto ">
<ItemTemplate >
<%# DataBinder.Eval (Container.Data Item,
"questionto ") %>
</ItemTemplate>
<EditItemTempla te>
<asp:Label id="lblFrom" text="Company: "
runat="server" />
<br />
<asp:DropDownLi st id="ddlTo" runat="server"
DataValueField= "cname" AutoPostBack="T rue" DataSource='<%#
GetCompanyNames ForThisProject( ) %>'
OnSelectedIndex Changed="ddlTo_ SelectedIndexCh anged" />
<asp:Label id="lblContact " text="Contact: "
runat="server" />
<br />
<asp:DropDownLi st id="ddlContact " runat="server"
DataValueField= "name" AutoPostBack="T rue" DataSource='<%#
GetContactsFrom CompanyForThisP roject() %>'/>
</EditItemTemplat e>
</asp:TemplateCol umn>

Apr 25 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1653
by: DotNetJunkies User | last post by:
Hie, I create a dynamique HtmlTable, in each cell of this HtmlTable put a new control ( dropdownlist,label,..) and then want to create handler so that if i change the select item in the dop downlist i change the text displayed in the label in the same row. hier is my code: using System; using System.Collections; using System.ComponentModel;...
2
1648
by: Sid | last post by:
Hi All, I am trying to populate a dropdown list in my Datagrid control using the OleDbDataReader, but when my function tries to add items to the dropdownlist it says that my dropdownlist control has not been 'declared' even though it is set to runat="server" . Any ideas?
18
2430
by: Julia Hu | last post by:
Hi, I have a datagrid, and in different rows I need to programmatically bind different type of controls and load data into these controls. For example,in the first row I need to bind data into a textbox, and in the second row I need to bind data into a dropdownlist...It all depends on the data I select from the database. I cannot use...
0
1524
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway when the user selects the first dropdownlist the dropdownselected_indexchanged is firring but when the user chagnes the second dropdownlist its not...
0
1816
by: Daniel Doyle | last post by:
Hello and apologies in advance for the amount of code in this post. I've also sent this message to the Sharepoint group, but thought that ASP.NET developers may also be able to help, even though it's a Sharepoint WebPart. I'm trying to do something fairly simple, create a datagrid that displays where and when a person works and allows them to...
1
2353
by: jimb | last post by:
I can get the dropdownlist into the datagrid, and I can populate it, but I can't read it. Anybody have a working example of a dropdownlist in an editable grid? Thanks. -- .. http://sf-f.org, weblog and search engine for fans and writers of
2
1724
by: Frank | last post by:
Hello, I am developing with VS.Net 2003 on the asp 1.1 platform. I am a few days new to using a datagrid. I found a nice tutorial and had no problems using an editable datagrid with textboxes and an additional buttoncolumn where I used a delete button to delete a specific row. Once I had finished that, I trnsformed the grid tso it will...
15
3086
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an OnSelectedIndex event is not fired if you select the first item. Does anyone know of an easy way to do this?
15
2161
by: Arpan | last post by:
Consider the following code which retrieves data from a SQL Server 2005 DB table & displays it in a DataGrid: <script runat="server"> Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) Dim dSet As DataSet Dim sqlConn As SqlConnection Dim sqlDapter As SqlDataAdapter sqlConn = New SqlConnection("Data Source=AD\SQLEXPRESS;Initial
0
7701
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7615
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8130
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3643
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2115
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
940
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.