2014-11-22 97 views
0

我試圖將圖像添加到一個單選按鈕列表控件,但它不工作..將圖片添加到一個單選按鈕列表在ASP.Net

我想這個..

RadioButtonList2。 Items.Add(new ListItem(String.Format(「src ='../Colors/Dallas_#625527_1.1.png'>」)));

但整個圖像標籤顯示爲文本

我想我的設計時間以及

<asp:RadioButtonList ID="rbListImages" runat="server"> 
    <asp:ListItem Text="One" Value="1"><img src="../Colors/Dallas_#625527_1.1.png" alt="" /></asp:ListItem> 
</asp:RadioButtonList> 

但它說img標籤不能被嵌套與列表項的標籤。請幫助我..

+0

這只是html5驗證,只是在瀏覽器中看到它應該是o k ... – 2014-11-22 10:30:07

+0

[在RadioButtonList控件中顯示圖像](http://www.c-sharpcorner.com/UploadFile/deepak.sharma00/display-images-in-radiobuttonlist-control-in-Asp-Net/) – 2014-11-22 11:03:43

+0

謝謝Vishal ..傻我.. – 2014-11-22 11:14:03

回答

6

您需要指定控件控件,您試圖設置src標籤,但沒有圖像控件。試試這個: -

RadioButtonList2.Items.Add(new ListItem("<img src='"+"../Colors/Dallas_#625527_1.1.png"+"'/>")); 

您也可以在設計時添加這個,像這樣: -

<asp:RadioButtonList ID="imagetest" runat="server"> 
     <asp:ListItem Text='<img src="Image1.jpg" alt="img1" />' Value="1" Selected="True" /> 
     <asp:ListItem Text='<img src="Image2.jpg" alt="img2" />' Value="2"></asp:ListItem> 
</asp:RadioButtonList> 
1
<asp:RadioButtonList ID="RadioButtonList1" runat="server" > 
<asp:ListItem Text="&lt;img src=&quot;Images/AddIcon.gif&quot;/&gt; Option1" Value="1"> </asp:ListItem> 

    <asp:ListItem Text="&lt;img src=&quot;Images/1.gif&quot;/&gt; Option2" Value="2"></asp:ListItem> 

    <asp:ListItem Text="&lt;img src=&quot;Images/2.gif&quot;/&gt; Option3" Value="3"></asp:ListItem> 

<asp:ListItem Text="&lt;img src=&quot;Images/3.gif&quot;/&gt; Option4" Value="4"></asp:ListItem> 

(OR) 另一種方式: 從代碼的背後: Display Images in RadioButtonList Control