如何用图片布局 ASP.Net 个单选按钮?

How to layout ASP.Net RadioButtons with Images?

我需要用图像布置 RabioButtons。但我不知道如何。我如何使用 ASP.Net RadioButtons 和 HTML/CSS.

实现图像中的布局

您可以参考这些链接来了解您想要实现的目标。这些可能会为您指明正确的方向。

Link 1

Link 2

Link 3

Link 4

希望这对您有所帮助。

<div>
<asp:RadioButtonList ID="myRadioBtnList" runat="server" >
<asp:ListItem Text="&lt;img src=&quot;download.jpg&quot;/&gt;" Value="1">         </asp:ListItem>
  <asp:ListItem Text="&lt;img src=&quot;download.jpg&quot;/&gt;" Value="2">   </asp:ListItem>
<asp:ListItem Text="&lt;img src=&quot;download.jpg&quot;/&gt;" Value="3"></asp:ListItem>
 <asp:ListItem Text="&lt;img src=&quot;download.jpg&quot;/&gt;" Value="4"></asp:ListItem>
 </asp:RadioButtonList>
    </div>

在文本 属性 中将 download.jpg 替换为您的图片路径。我想这会对你有所帮助

试试这个

   protected void Page_Load(object sender, EventArgs e)
{
    ListItem item;
    int i = 0;
    System.IO.FileInfo file;

    var Images =
        from n in System.IO.Directory.GetFiles(Server.MapPath("Images"))
        orderby n descending
        select n;

    foreach (var filename in Images)
    {
        file = new System.IO.FileInfo(filename);

        item = new ListItem("<img src='" + "Images/" + file.Name + "' alt='" + file.Name +
            "' title='"+file.Name+"'/>", i.ToString());

        RadioButtonList1.Items.Add(item);
        RadioButtonList1.CellPadding = 5;
        RadioButtonList1.CellSpacing = 5;
        i++;
    }
}


    <div>
    <asp:RadioButtonList ID="RadioButtonList1"
        runat="server"
        BorderStyle="Groove"
        BorderWidth="1px"
        RepeatColumns="3"
        RepeatLayout="Table">
    </asp:RadioButtonList> 
</div>

Source