asp.net – DropDownList selectedvalue和表

问:

嗨,我有一个下拉列表,我得到两个错误.

错误#1:我的要求是从下拉列表中选择会议名称,将其保存为字符串并稍后使用该字符串.我想从数据库表中获取字段值(它给出了存储文件的路径).

代码 :

string selected = DropDownList1.SelectedValue.ToString();

var query = from meet in db.Meets
            where meet.Summary = selected
            select meet.Doc_Path;

我在“Where.Summary = selected”的地方收到错误,它说

“cannot implicitly convert type string
to bool”

错误#2:我希望使用我通过查询获得的Doc_Path值.我不确定语法,因此在我尝试时出错.

代码:

string[] dirs = Directory.GetDirectories(query);

请帮忙.

最佳答案 错误#1 – 我认为你需要==而不仅仅是=

string selected = DropDownList1.SelectedValue.ToString();

var query = from meet in db.Meets
            where meet.Summary == selected
            select meet.Doc_Path;

错误#2 – 您可能需要使用Server.MapPath

String FilePath;
FilePath = Server.MapPath(query);

或者,将它们结合起来

string selected = DropDownList1.SelectedValue.ToString();

var query = from meet in db.Meets
            where meet.Summary == selected
            select Server.MapPath(meet.Doc_Path);

string[] dirs = Directory.GetDirectories(query);
点赞