asp.net图像src未在listview

时间:2017-05-20 13:59:25

标签: c# asp.net listview

我面临着非常严重的问题。我试图使用listview控件绑定数据库中的图像路径。 Listview获取绑定但img没有显示。当我查看检查时,我无法在img标签中看到src属性。 Listview完美绑定,路径也正确。如果你看到下面的截图&看到突出显示的行,即缺少src属性的img标记。 enter image description here

<div class="row">
        <asp:ListView ID="subCategoriesList" runat="server">
            <ItemTemplate>
                <div class="col-md-3">
                        <img id="myimag" runat="server" src='<%# Eval("icon") %>' />
                        <br /><%# Eval("name") %>
                </div>
            </ItemTemplate>
        </asp:ListView>
    </div>

ListviewBind代码

private void bindSubCatgoriesRightSide()
{
    try {
        string constr = ConfigurationManager.ConnectionStrings("conio2").ConnectionString;
        using (MySqlConnection con = new MySqlConnection(constr)) {
            using (MySqlCommand cmd = new MySqlCommand()) {
                cmd.CommandText = "SELECT * FROM subcategory WHERE type = 'product' and category = 'mobile' and status = 'active'";
                cmd.Connection = con;
                using (MySqlDataAdapter sda = new MySqlDataAdapter(cmd)) {
                    DataTable dt = new DataTable();
                    sda.Fill(dt);
                    subCategoriesList.DataSource = dt;
                    subCategoriesList.DataBind();
                }
            }
        }
    } catch (Exception ex) {
        Response.Write(ex);
    }
}

1 个答案:

答案 0 :(得分:0)

我认为您正在查看错误的输出部分,在listview项目模板中,您将图像包裹在<div class="col-md-3"></div ...

但在屏幕截图中,图片包含在<div class="col-md-6 col-sm-6 col-xs-12 margin-bottom"></div

除非你用JS改变类