如何在数据列表控件中显示数据库中的数据

本文关键字:数据 显示 数据库 列表 控件 | 更新日期: 2023-09-27 17:55:08

我有一个项目,我正在处理管理界面。在管理界面中,我必须执行以下工作。

  • 允许用户选择其中的表他想表演操作(删除,显示,更新)。

  • 在保存用户信息时。 我是保存图像路径。我必须也因此在管理中的用户图像与用户 ID 相关的接口。

问题是我有保存图像路径。 并且我必须在数据列表控件中显示图像。任何人都可以建议我如何执行此任务吗?我必须通过源代码使用数据列表。

如何在数据列表控件中显示数据库中的数据

好吧

,如果我完全理解你,你想要一个图像下拉列表,据我所知,这是不可能的。您可以做的是创建一个数据绑定下拉列表和图像控件,该下拉列表将显示下拉列表中选择的图像,如下所示:

    SqlDataSource yourDataSource = new SqlDataSource("your connection string here", "select command here. Something like 'SELECT id, image FROM table'");
    DropDownList yourDropDown = new DropDownList();
    yourDropDown.DataSource = yourDataSource;
    // makes the dropdown show the id but the value will return the image value
    yourDropDown.DataTextField = "id";
    yourDropDown.DataValueField = "image";
    yourDropDown.DataBind();
    Image img = new Image();
    img.ImageUrl = yourDropDown.SelectedValue;

然后,您可以更新 ImageURL 属性 OnIndexChanged。

祝你好运, 迈克尔