Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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 8-Nov-12 16:23pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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




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
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...........
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

DOne Smile | :)



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 Smile | :)
  Permalink  
v2

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 144
1 Sascha Lefévre 100
2 OriginalGriff 90
3 Abhinav S 84
4 Maciej Los 84
0 Sergey Alexandrovich Kryukov 6,578
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Abhinav S 2,358
4 Maciej Los 2,352


Advertise | Privacy | Mobile
Web02 | 2.8.150414.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100