G
Guest
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) GetCompanyNamesForThisProject
2) GetContactsFromCompanyForThisProject
3) ddlTo_SelectedIndexChanged
Function GetCompanyNamesForThisProject() as DataSet
dsCompanyNames.Clear()
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data
Source=c:\sites\single29\gmeadows73\database\fdmdb.mdb"
Dim queryString As String = "SELECT DISTINCT [users].[cname] FROM
[users] WHERE ([users].[project] = '" & Session("project") & "')"
Dim dataAdapter As New OleDbDataAdapter (querystring, strConnString)
dataAdapter.Fill(dsCompanyNames, "users
Return dsCompanyNames
End Function
Function GetContactsFromCompanyForThisProject () As DataSet
' dsContacts.Clear()
Dim strConnString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\sites\single29\gmeadows73\database\fdmdb.mdb"
Dim queryString As String
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("project") & "'))"
Dim dataAdapter As New OleDbDataAdapter (queryString,
strConnString)
dataAdapter.Fill(dsContacts, "users")
Return dsContacts
End Function
Sub ddlTo_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName = list.SelectedItem.Text
Dim ddlContact As DropDownList = CType(sender, DropDownList)
ddlContact.DataSource = GetContactsFromCompanyForThisProject ()
ddlContact.DataBind ( )
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:TemplateColumn HeaderText="To"
SortExpression="questionto">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
"questionto") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="lblFrom" text="Company: "
runat="server" />
<br />
<aspropDownList id="ddlTo" runat="server"
DataValueField="cname" AutoPostBack="True" DataSource='<%#
GetCompanyNamesForThisProject() %>'
OnSelectedIndexChanged="ddlTo_SelectedIndexChanged" />
<asp:Label id="lblContact" text="Contact: "
runat="server" />
<br />
<aspropDownList id="ddlContact" runat="server"
DataValueField="name" AutoPostBack="True" DataSource='<%#
GetContactsFromCompanyForThisProject() %>'/>
</EditItemTemplate>
</asp:TemplateColumn>
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) GetCompanyNamesForThisProject
2) GetContactsFromCompanyForThisProject
3) ddlTo_SelectedIndexChanged
Function GetCompanyNamesForThisProject() as DataSet
dsCompanyNames.Clear()
Dim strConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;
Ole DB Services=-4; Data
Source=c:\sites\single29\gmeadows73\database\fdmdb.mdb"
Dim queryString As String = "SELECT DISTINCT [users].[cname] FROM
[users] WHERE ([users].[project] = '" & Session("project") & "')"
Dim dataAdapter As New OleDbDataAdapter (querystring, strConnString)
dataAdapter.Fill(dsCompanyNames, "users
Return dsCompanyNames
End Function
Function GetContactsFromCompanyForThisProject () As DataSet
' dsContacts.Clear()
Dim strConnString As String =
"Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data
Source=C:\sites\single29\gmeadows73\database\fdmdb.mdb"
Dim queryString As String
queryString = "SELECT [users].[name] FROM [users] WHERE
(([users].[cname] = '" & coName & "') AND ([users].[project] = '" &
Session("project") & "'))"
Dim dataAdapter As New OleDbDataAdapter (queryString,
strConnString)
dataAdapter.Fill(dsContacts, "users")
Return dsContacts
End Function
Sub ddlTo_SelectedIndexChanged(sender As Object, e As EventArgs)
Dim list As DropDownList = CType(sender, DropDownList)
coName = list.SelectedItem.Text
Dim ddlContact As DropDownList = CType(sender, DropDownList)
ddlContact.DataSource = GetContactsFromCompanyForThisProject ()
ddlContact.DataBind ( )
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:TemplateColumn HeaderText="To"
SortExpression="questionto">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,
"questionto") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Label id="lblFrom" text="Company: "
runat="server" />
<br />
<aspropDownList id="ddlTo" runat="server"
DataValueField="cname" AutoPostBack="True" DataSource='<%#
GetCompanyNamesForThisProject() %>'
OnSelectedIndexChanged="ddlTo_SelectedIndexChanged" />
<asp:Label id="lblContact" text="Contact: "
runat="server" />
<br />
<aspropDownList id="ddlContact" runat="server"
DataValueField="name" AutoPostBack="True" DataSource='<%#
GetContactsFromCompanyForThisProject() %>'/>
</EditItemTemplate>
</asp:TemplateColumn>