Click here to Skip to main content
15,900,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i created my Select stored Procedyre
then i create a (LINQ to SQL class ) file .. drag and drop stored procedures to convert them into classes

i want to receive a column of table into a (drop down list)


Code in Page load
DataClass1DataContext countries = new DataClassesDataContext();


i do not know how to receive returned data into DropdownList

is it by using DataSeT ??!! and if it , how in code ?

thanks
Posted

take a dropdown list box
drag it in asp.net webpage i.e aspx page or design page

page load event write

load_dropdown()



then




VB
Protected Sub load_dropdown()
        Dim sqlselect As String
        
            sqlselect = " SELECT columan_name FROM table_name "
            ds = Utility.ExecuteDataset(ConnectionString, CommandType.Text, sqlselect)
            ddlblockperiod.DataSource = ds
            ddlblockperiod.DataValueField = column_id;
            ddlblockperiod.DataTextField = column_name;
            ddlblockperiod.DataBind()
            ds.Dispose()

End Sub
 
Share this answer
 
v2
Var id=(from a in linq_obj.table name
Select new
{
Intglcode=a.intglcode,
columnname =a.columnname
}).Tolist();
ddlblockperiod.Datasource=id;
ddlblockperiod.DataValueField = column_id;
ddlblockperiod.DataTextField = column_name;
ddlblockperiod.Databind();

try this...........
 
Share this answer
 
DOne :)



protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataClassesDataContext countries = new DataClassesDataContext();
            DropDownList1.DataSource = countries.SelectCountries();
            DropDownList1.DataTextField = "CountryName";
            DropDownList1.DataBind();
        }
    }



As
DataClassesDataContext
>>> is a Link to SQL Classes
&
SelectCountries
>>>> is a class in
DataClassesDataContext
, that Select all countries from countries table
&
CountryName
>>> is the selected column from countries table


Thanks all for answers :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900