Answered by:
Get value from DropDownList

Question
-
User791350511 posted
Hi,
I use the following code to fill a DropDownList box:
<asp:DropDownList ID="ddlLocationSystems" runat="server" Width="302px" DataSourceID="SqlDataSourceLocationSystems" DataTextField="LocSysName" DataValueField="LocationSystemsID" Font-Names="Tahoma" OnSelectedIndexChanged="ddlLocationSystems_SelectedIndexChanged"> </asp:DropDownList>
...
<asp:SqlDataSource ID="SqlDataSourceLocationSystems" runat="server" ConnectionString="<%$ ConnectionStrings:LocalSQLServer %>" SelectCommand="SELECT [LocationSystemsID], [LocationName] + '\' + [SystemName] as LocSysName FROM [LocationSystems] WHERE ([SiteID] = @SiteID)"> <SelectParameters> <asp:ControlParameter ControlID="ddlSites" Name="SiteID" PropertyName="SelectedValue" /> </SelectParameters>
This works fine but I want to be able to get the LocationSystemsID from the current selection in the DropDownList box. If I try and access ddlLocationSystems.DataValueField I get 'LocationSystemsID' and not the current Guid for the LocationSystem I am looking for?
LocationSystems table
LocationSystemsID - Guid (PK)
LocationName - nvarchar(50)
SystemName - nvarchar(50)
SiteID - Guid
Any help appreciated.
Thanks
Paul.
Tuesday, December 2, 2014 3:53 AM
Answers
-
User-1716253493 posted
I guess you can get it by ddlLocationSystems.SelectedValue
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2014 3:57 AM -
User-1716253493 posted
To get data from SqlDataSource you can use : Dim dt as DataTable = ctype(Sqlds2.Select(DataSaurceSelecArgument.Empty), DataView).Table, filter the SqlDataSource by the DropDownList as SelectParameter ControlParameter. Add another SqlDataSource filtered by DropDownList.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2014 9:42 AM
All replies
-
User-1716253493 posted
I guess you can get it by ddlLocationSystems.SelectedValue
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2014 3:57 AM -
User-1569093213 posted
try like this
ddlLocationSystems.selectedValue.
ddlLocationSystems.selectedItem.Text
Tuesday, December 2, 2014 4:04 AM -
User791350511 posted
oned_gk,
Thanks for the reply. I can get the text from the DropDownList its the associated LocationSystemsID (Guid) I want. Can I retrieve it somehow from the SQLDataSourceLocationSystems?
Thanks
Paul.
Tuesday, December 2, 2014 5:00 AM -
User-1569093213 posted
DropDownList1.SelectedIndex
Tuesday, December 2, 2014 6:41 AM -
User791350511 posted
bhushan_Microsoft,
Thanks for the reply. DropDownList1.SelectedIndex just gets me the index not the required associated Guid.
Thanks
Paul.
Tuesday, December 2, 2014 6:57 AM -
User-1716253493 posted
To get data from SqlDataSource you can use : Dim dt as DataTable = ctype(Sqlds2.Select(DataSaurceSelecArgument.Empty), DataView).Table, filter the SqlDataSource by the DropDownList as SelectParameter ControlParameter. Add another SqlDataSource filtered by DropDownList.- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, December 2, 2014 9:42 AM