DropDownList 选定的值和表格

发布于 2024-11-04 10:23:26 字数 702 浏览 0 评论 0原文

问:

嗨,我有一个下拉列表,但出现两个错误。

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

代码:

string selected = DropDownList1.SelectedValue.ToString();

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

我在“where meet.Summary=selected”处收到错误,它显示

“无法隐式转换字符串类型 布尔”

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

代码:

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

请帮忙。

Q:

Hi,I have a dropdownlist and i get two errors.

Error #1: My requirement is selecting the meeting name from the dropdownlist, saving it into a string and using that string later. I want to get the field value (which gives me the path where the files are stored) from the database table.

The code :

string selected = DropDownList1.SelectedValue.ToString();

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

I get an error at "where meet.Summary=selected" and it says

"cannot implicitly convert type string
to bool"

Error #2: I wish to use the Doc_Path value which I get through the query. I am not sure of the syntax and hence getting an error when I tried it.

The code:

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

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

青春如此纠结 2024-11-11 10:23:26

错误 #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);

Error # 1 - I think you need == instead of just =

string selected = DropDownList1.SelectedValue.ToString();

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

Error #2 - You may need to user Server.MapPath

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

or, to combine them

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);
梦途 2024-11-11 10:23:26

错误#1:

正如之前所说,在进行比较时应该使用==而不是=

错误#2:

为什么使用Directory.GetDirectories(query);

前面的方法用于获取指定目录中的子目录名称(包括其路径)。

看看这里

我认为你不需要这个方法,只需使用:

string selected = DropDownList1.SelectedValue.ToString();

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

string dirPath = System.Web.HttpContext.Current.Server.MapPath("~") + query.ToString();

确保 meet.Doc_Path 值不是绝对路径,仅存储相对路径。

Error # 1:

As said before ,you should use == instead of = when making comparison .

Error # 2:

Why you use Directory.GetDirectories(query);

the previous method is used to Get the names of subdirectories (including their paths) in the specified directory.

look here

i think you don't need this method, just use :

string selected = DropDownList1.SelectedValue.ToString();

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

string dirPath = System.Web.HttpContext.Current.Server.MapPath("~") + query.ToString();

Make sure that the meet.Doc_Path value is n't the absolute path, store only the relative path.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文