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

时间:2011-05-07 09:30:16

标签: c# asp.net

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

  • 允许用户选择其中的表格 他想表演 动作(delte,显示,更新)。

  • 保存用户信息。我是 保存图像路径。我必须 也是管理员中的用户图像 关于用户ID的界面。

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

1 个答案:

答案 0 :(得分:0)

好吧,如果我理解你,你需要一个图片下拉,据我所知,这是不可能的。 你可以做的是创建一个数据绑定下拉和图像controll,它将显示在下拉列表中选择的图像,如下所示:

    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。

祝你好运,               迈克尔