从sql DB接收数据到下拉列表 [英] Receive data from sql DB into Dropdown List

查看:63
本文介绍了从sql DB接收数据到下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了我的选择存储过程"
然后创建一个(LINQ to SQL类)文件..拖放存储过程以将其转换为类

我想在(下拉列表)中收到一列表格


页面加载中的代码
DataClass1DataContext国家=新的DataClassesDataContext();


我不知道如何将返回的数据接收到DropdownList中

是通过使用DataSeT吗?如果有的话,如何编写代码?

感谢

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

推荐答案

选择一个下拉列表框
将其拖动到asp.net网页(即aspx页面或设计页面)中

页面加载事件写入

load_dropdown()



然后




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


Var id =(from linq_obj.table中的a
选择新的
{
Intglcode = a.intglcode,
columnname = a.columnname
}).Tolist();
ddlblockperiod.Datasource = id;
ddlblockperiod.DataValueField = column_id;
ddlblockperiod.DataTextField = column_name;
ddlblockperiod.Databind();

试试这个...........
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...........


DOne :)



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

>>>是SQL类的链接
&

>>> 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 :)


这篇关于从sql DB接收数据到下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆