Populate Dropdown list

pragya163

New member
Joined
Sep 20, 2013
Messages
3
Programming Experience
1-3
I am trying to populate a dropdown list (year which is a FK in a budget table) The year has the following fields (Objectuid uniqueidentifier (PK), name varchar(30), IsActive,IsDeleted.......). The budget table has (Objectuid Uniqueidentifier (PK), yearID uniqueidentifier (FK), name, ......)

The yearID field in the Budget page displays all the Names currently. I want to show Only those items in YearID that are ISACTIVE=1 in the database). I want to do this on a Load page.

How can I achieve this ?
 

speshulk92683

Member
Joined
Oct 25, 2013
Messages
5
Programming Experience
5-10
I would first create a stored procedure that pulls the data how you want it. "SELECT [fieldnames] FROM Budget WHERE ISACTIVE = 1".

then you can create a SqlDataSource property on your aspx page like this:
VB.NET:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="sp_StoredProcedureName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

Then you connect that SqlDataSource to your dropdownlist. Replace "TextFieldName" with the name of the field you want displayed. Replace "ValueFieldName" with the field name you want as the value.
VB.NET:
<asp:DropDownList ID="ddlBudget" runat="server" DataSourceID="SqlDataSource1" DataTextField="TextFieldName" DataValueField="ValueFieldName">
                        </asp:DropDownList>
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,602
Location
Sydney, Australia
Programming Experience
10+
I would first create a stored procedure that pulls the data how you want it. "SELECT [fieldnames] FROM Budget WHERE ISACTIVE = 1".

then you can create a SqlDataSource property on your aspx page like this:
VB.NET:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="sp_StoredProcedureName" SelectCommandType="StoredProcedure"></asp:SqlDataSource>

Then you connect that SqlDataSource to your dropdownlist. Replace "TextFieldName" with the name of the field you want displayed. Replace "ValueFieldName" with the field name you want as the value.
VB.NET:
<asp:DropDownList ID="ddlBudget" runat="server" DataSourceID="SqlDataSource1" DataTextField="TextFieldName" DataValueField="ValueFieldName">
                        </asp:DropDownList>

There's no need to create a stored procedure if you don't already have one. The important thing to note here is the WHERE clause. You simply add that WHERE clause to whatever query you're using now and it will work as you want.
 
Top Bottom