【问题标题】:Asp.net Gridview templatefield line break not workingAsp.net Gridview 模板字段换行符不起作用
【发布时间】:2015-11-03 04:19:15
【问题描述】:

我在 gridview 模板字段中有一个图像和一个标签。

<asp:TemplateField HeaderText = "Rate" >
    <ItemTemplate>
       <asp:Image ID="imgID" runat="server" />
        <asp:Label id="ImageNameLabel" Text="" runat="server" /> 
     </ItemTemplate>
</asp:TemplateField>

代码隐藏

if (e.Row.RowType == DataControlRowType.DataRow)
{
    Image img = (Image)e.Row.FindControl("imgID");
    img.ImageUrl = "~/Images/s1.png";
    img.Height = 80;
    img.Width = 80;
    e.Row.Cells[6].Controls.Add(img);
    Label lbl = (Label)e.Row.FindControl("ImageNameLabel")  
    lbl.Text = "Image Name Here";
}

当我运行应用程序时,图像和标签都显示在彼此旁边。我希望标签位于图像的正下方。

如果我添加这个

lbl.Text = "Image Name Here" + "<br/>";

然后它会反过来(标签在顶部,图像在底部)。

如何将标签移到图片正下方?

【问题讨论】:

    标签: c# asp.net gridview templatefield


    【解决方案1】:

    试试这个,它应该可以工作。

    <asp:TemplateField HeaderText = "Rate" >
    <ItemTemplate>
    <table>
    <tr>
      <td align="center">
       <asp:Image ID="imgID" runat="server" />
      </td>
    </tr>
    <tr>
      <td>
        <asp:Label id="ImageNameLabel" Text="" runat="server" /> 
      </td>
    </tr>
    </table>
    </ItemTemplate>
    </asp:TemplateField>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-04
      • 1970-01-01
      相关资源
      最近更新 更多