lesmydad
asked on
retriving data from database to dropdown list
Hi Guys,
I have two database table tblTelephoneSuppliers and tblTelephoneCallPlans. tblTelephoneCallPlans which has fileds TelephoneCallPlansID, TelephoneSuppliersID and TelephoneCallPlanName. tblTelephoneSuppliers has fields tblTelephoneSuppliersID and TelephoneSupplierName.
I have a dropdown list which retrive all the telephone suppliers from tblTelephoneSuppliers on that dropdown list. I also have another dropdown box. What i want is when a selected item is selected from the dropdown list, the call plan for that supplier to be shown on dropdown list 2.
I've done the store procedure like this:
CREATE Procedure sp_getTelephoneCallPlans
@TelephoneSupplierID int
AS
Select Distinct
TelephoneCallPlanName
From tblTelephoneCallPlans TS
Where
Enabled <> 0
AND
TS.TelephoneSupplierID = @TelephoneSupplierID
the drop down supplier list store procedure is done like this:
CREATE Procedure sp_getSecondSupplier
AS
SELECT
TelephoneSupplierName
FROM
tblTelephoneSuppliers
WHERE
Enabled <> 0;
Now how would i do the backend and front end coding so when a value from dropdown list 1 is selected its correspondent plans to be shown on dropdown list 2.
Thanks,
Les
I have two database table tblTelephoneSuppliers and tblTelephoneCallPlans. tblTelephoneCallPlans which has fileds TelephoneCallPlansID, TelephoneSuppliersID and TelephoneCallPlanName. tblTelephoneSuppliers has fields tblTelephoneSuppliersID and TelephoneSupplierName.
I have a dropdown list which retrive all the telephone suppliers from tblTelephoneSuppliers on that dropdown list. I also have another dropdown box. What i want is when a selected item is selected from the dropdown list, the call plan for that supplier to be shown on dropdown list 2.
I've done the store procedure like this:
CREATE Procedure sp_getTelephoneCallPlans
@TelephoneSupplierID int
AS
Select Distinct
TelephoneCallPlanName
From tblTelephoneCallPlans TS
Where
Enabled <> 0
AND
TS.TelephoneSupplierID = @TelephoneSupplierID
the drop down supplier list store procedure is done like this:
CREATE Procedure sp_getSecondSupplier
AS
SELECT
TelephoneSupplierName
FROM
tblTelephoneSuppliers
WHERE
Enabled <> 0;
Now how would i do the backend and front end coding so when a value from dropdown list 1 is selected its correspondent plans to be shown on dropdown list 2.
Thanks,
Les
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thi sis how i did it:
Private Sub secondsupplier_SelectedInd exChanged( ByVal sender As Object, ByVal e As System.EventArgs) Handles secondsupplier.SelectedInd exChanged
Dim TelephoneSupplierID As Integer
TelephoneSupplierID = secondplanname.SelectedInd ex
'Code to execute sp_getTelephonePlans and bind to combo 2
End Sub
but still the list of plans are not shown on dropdownl list2 when a option from dropdown list is executed
Private Sub secondsupplier_SelectedInd
Dim TelephoneSupplierID As Integer
TelephoneSupplierID = secondplanname.SelectedInd
'Code to execute sp_getTelephonePlans and bind to combo 2
End Sub
but still the list of plans are not shown on dropdownl list2 when a option from dropdown list is executed
Oh ... this is a VB forum ... but ASP is ok.
You would retrieve it from the DataValueField which should equal "TelephoneSupplierID"
Racin
You would retrieve it from the DataValueField which should equal "TelephoneSupplierID"
Racin
ASKER
Sorry did not recognise as VB forum
In combobox 2 i inserted these DataValueField="TelephoneC allPlanNam e" DataTextField="TelephoneCa llPlanName " to the webform but still have no luck. I also tested with "TelephoneSupplierID" but does not functions.
Any other idea.
thanks
les
In combobox 2 i inserted these DataValueField="TelephoneC
Any other idea.
thanks
les
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry, that should be
MyList.DataSource = Ctype(SQLData.CreateDate(" sp_getTele phonePlans ", objconn, SQLType.BindingData), DataView)
MyList.DataBind
MyList.DataSource = Ctype(SQLData.CreateDate("
MyList.DataBind
ASKER
Hi platinumbay,
I dont need the sql connection and retrival stuffs as i already have done them separately on the dataprovider.vb through the store procedure. I'm using VS.Studio.
Connection and store procedure works perfectly.
The dorpdown list two needs to show the values accordinarly to dropdown list 1. At the moment its like this:
<asp:DropDownList id="secondsupplier" DataValueField="TelephoneS upplierID" DataTextField="TelephoneSu pplierName " AutoPostBack="True" Runat="server"></asp:DropD ownList>
<asp:DropDownList id="secondplanname" AutoPostBack="True" Runat="server" DataValueField="TelephoneS upplierID" DataTextField="TelephoneCa llPlanName "></asp:Dr opDownList >
what do i need to change there or the store procedure to make this function - do i need to add exetra bvits of cod eon my back end script
Thanks
I dont need the sql connection and retrival stuffs as i already have done them separately on the dataprovider.vb through the store procedure. I'm using VS.Studio.
Connection and store procedure works perfectly.
The dorpdown list two needs to show the values accordinarly to dropdown list 1. At the moment its like this:
<asp:DropDownList id="secondsupplier" DataValueField="TelephoneS
<asp:DropDownList id="secondplanname" AutoPostBack="True" Runat="server" DataValueField="TelephoneS
what do i need to change there or the store procedure to make this function - do i need to add exetra bvits of cod eon my back end script
Thanks
Use the postback event handler for dropdown 1 to populate dropdown 2. Double-click on dropdown list 1 to create the method in VS.NET. Then add your code to populate List 2 based on the selection in list 1.
ASKER
After hours of test and trial i manage to write the script:
VB.NET part:
Private Sub secondsupplier_SelectedInd exChanged( ByVal sender As Object, ByVal e As System.EventArgs) Handles secondsupplier.SelectedInd exChanged
Dim TelephoneSupplierID As Integer
Dim DataSource
TelephoneSupplierID = secondsupplier.SelectedIte m.Value
dtSecondPlan = FRI.SOMB.Visitor.DataProvi der.getSec ondPlan(Te lephoneSup plierID)
secondplanname.DataSource = dtSecondPlan
secondplanname.DataBind()
End Sub
ASP.NET form script:
<asp:DropDownList id="secondsupplier" DataValueField="TelephoneS upplierID" DataTextField="TelephoneSu pplierName " AutoPostBack="True" Runat="server" ><asp:listitem Text="Please Select..."/></asp:DropDown List></asp :Label></d iv>
<div><asp:Label ID="callplan" Runat="server" Text="What is the name of the call plan you are on?" >
<asp:DropDownList id="secondplanname" Runat="server" DataValueField="TelephoneC allPlanNam e" DataTextField="TelephoneCa llPlanName ">
</asp:DropDownList>
</asp:Label></div>
Thanks to all these who tried to help
Les
VB.NET part:
Private Sub secondsupplier_SelectedInd
Dim TelephoneSupplierID As Integer
Dim DataSource
TelephoneSupplierID = secondsupplier.SelectedIte
dtSecondPlan = FRI.SOMB.Visitor.DataProvi
secondplanname.DataSource = dtSecondPlan
secondplanname.DataBind()
End Sub
ASP.NET form script:
<asp:DropDownList id="secondsupplier" DataValueField="TelephoneS
<div><asp:Label ID="callplan" Runat="server" Text="What is the name of the call plan you are on?" >
<asp:DropDownList id="secondplanname" Runat="server" DataValueField="TelephoneC
</asp:DropDownList>
</asp:Label></div>
Thanks to all these who tried to help
Les
ASKER
Also what i would need to do on the web form. It construcfted like this:
Drop Down List one:
<asp:DropDownList id="secondsupplier" DataValueField="TelephoneS
This is retriving values from the second procedure on the option list.
Drop Down List Two
<asp:DropDownList id="secondplanname" AutoPostBack="True" Runat="server"></asp:DropD
by the way its not combobox its dropdown list