select Preacher_Id , Name from Preacher_SkillDetail
where Preacher_Id not in (
where Preacher_FK from Event_Preacher
where (@newstartdate <= Start_Date and @newenddate >= Start_Date)
or (@newstartdate <= End_Date and @newenddate >= End_Date)
or (@newstartdate >= End_Date and @newenddate <= End_Date)
or (@newstartdate <= Start_Date and @newenddate >= End_Date)
)
我希望bind the output
改为ropdowncontrol
我怎样才能在c#.net中做到这一点?我有变量newstartdate and newenddate as Date
答案 0 :(得分:1)
DataTable GetData() {
SqlConnection connection=new SqlConnection();
connection.ConnectionString="Put your connection string";
SqlCommand command = connection.CreateCommand();
command.CommandText = "Your Sql Query Geos here";
DataTable dt = new DataTable();
try
{
command.Connection.Open();
dt.Load(command.ExecuteReader());
}
catch (Exception ex)
{
// Log ur error;
}
finally {
connection.Close();
}
return dt;
}
然后
Dropdownlist.Datasource=GetData();
Dropdownlist.DataBind();
在控件属性中指定文本字段和值字段。
我认为这应该有用。
答案 1 :(得分:0)
您必须绑定下拉列表的DataTextField和DataValueField。 DataTextField是显示下拉列表中元素的字段。 DataValueField保存这些字段的ID。 如果您的查询返回类似的内容 Peacher_id |名称 1 | Peacher 1 2 | Peacher 2 3 | Peacher 3 理想情况下,Peacher_Id应绑定到DataValueField,Name应绑定到DataTextField。您可以转到下拉列表属性并设置这些属性。之后,您只需将数据源绑定到下拉列表。
dropdownlist.DataSource = ds; dropdownlist.DataBind();