[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 411
  • Last Modified:

populating dependent dropdown list from a table in oracle.

Hi,
how to populate dependent dropdownlist from oracle database table.
i have 2 dropdownlist one used for country and other for state.if user selects dropdownlist country as southamerica then states in southamerica should be populated in second dropdownlist.
Thank you
using asp.net/oracle/.net2.0
0
tracy_p
Asked:
tracy_p
  • 2
  • 2
1 Solution
 
oleggoldCommented:
0
 
oleggoldCommented:
<aspataGrid id="Datagrid2" runat="server" Cssclass="txtTen" Width="600px"
Height="35px" Font-Size="9px" Font-Names="Verdana"
AutoGenerateColumns="False" Visible="True" BackColor="#FCFBEB"
BorderColor="#FFC0C0">

<HeaderStyle Font-Size="9px" Font-Names="Verdana"
Font-Bold="True"></HeaderStyle>

<Columns>
<asp:TemplateColumn HeaderText="Hotel Type">
<ItemTemplate>
<aspropDownList id="ddlhtype" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px" AutoPostBack="true" >
<asp:ListItem Value="Hotel Type">Hotel Type</asp:ListItem>
</aspropDownList>
</ItemTemplate>
</asp:TemplateColumn>

<asp:TemplateColumn HeaderText="Hotel name">
<ItemTemplate>
<aspropDownList id="ddlhname" runat="server" Font-Size="9px"
Font-Names="Verdana" Width="100px"></aspropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</aspataGrid>

my code behind for the grid goes like this
Private Sub Datagrid2_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles Datagrid2.ItemCreated

If Not e.Item.FindControl("ddlhtype") Is Nothing Then
AddHandler CType(e.Item.FindControl("ddlhtype"),
DropDownList).SelectedIndexChanged, AddressOf GetHotelNames
End If

End Sub

the handler definition goes like this



Public Sub GetHotelNames(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim quotemgr As New QuotationManager
Dim objcitystop As New CitystopServicesBE
objcitystop.ServiceCode = "CITYSTOP"
objcitystop.detailcode = "HTNM"
 
If Not CType(Datagrid2.FindControl("ddlhtype"), DropDownList) Is
Nothing Then
Dim strname As String
strname = CType(sender, DropDownList).SelectedValue.ToString()
objcitystop.Filter = strname
 
Dim col As New Collection
If Not CType(e.Item.FindControl("ddlhtype"),
DropDownList) Is Nothing Then
 
col = quotemgr.getcitystopdetails(objcitystop)
Dim objcity As CitystopServicesBE
For Each objcity In col
Dim strcode As New ListItem
strcode.Text = objcity.desc
strcode.Value = objcity.serviceid
Response.Write("before ddlname <br>")
 
If Not CType(Datagrid2.FindControl("ddlhname"),
DropDownList) Is Nothing Then
CType(Datagrid2.FindControl("ddlhname"),
DropDownList).Items.Add(strcode)
End If
Next
End If
 
 
 
Catch ex As Exception
Response.Write(ex.ToString)
End Try

Open in new window

0
 
vs1784Commented:
If you are using ASP.NET 2.0 you can use Ajax Control Toolkit.

It has cascading drop down control which can do exactly the same work for you, please check below link for example

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/CascadingDropDown/CascadingDropDown.aspx

Thanks
0
 
tracy_pAuthor Commented:
Thanks oleggold and vs1784.
i would i to use cascading dropdown control of ajax.
i have seen the weblink .i have 2 doubts.
can i use data in database table for populating instead of writing everything in xml file(as i have abt 70 items).
is it mandatory to write webservice?
thank you.
0
 
vs1784Commented:
It is not necessary to write web service. You can use page method instead which can be written on same page.

You can use database as well, below is the link for database binding.

http://www.asp.net/AJAX/AjaxControlToolkit/Samples/Walkthrough/CCDWithDB.aspx

Hope it helps
Thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now