如何将图像添加到Radiobuttonlist. [英] How to add Image to Radiobuttonlist.

查看:53
本文介绍了如何将图像添加到Radiobuttonlist.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我想将图像添加到单选按钮列表的项目中.这些图像的路径存储在数据库中,该数据库正在检索并存储在数据表中.

我有以下代码,但是以某种方式无法显示图像.

Hello Friends,

I want to add images to the items of radiobuttonlist.The path for these images is stored into the database which I am retrieving and storing in data table.

I have the following code but somehow the images are not getting displayed.

for (int i = 0; i < 4; i++)
           {
               data = anstable.Rows[answercount][2].ToString();
               if (data.Contains(@"\includegraphics[]"))
               {
                   url = objIO.GetStringInBetweenExclusive("{", "}", temp[1]);
                   string imagefolder = "~/images/";
                   this.RadioButtonList2.Items.Add(new ListItem(String.Format("<img src='{0}'>", imagefolder + url.ToString()), "image" + i.ToString()));
               }
               else
               {
                   RadioButtonList1.Items.Add(anstable.Rows[answercount][2].ToString());
                   answercount++;
               }
           }



谁能告诉我我的代码有什么问题吗?



Can anyone tell me whats wrong with my code?

推荐答案

您的代码看起来不错.此处提供了一个类似的示例:
http://www.codenewsgroups.net/aspnetwebcontrols/t5289-solution-radiobuttonlist-with- images.aspx [ ^ ]

我认为您需要检查图片网址并检查是否正确.您始终可以尝试在浏览器中输入该URL作为地址.

祝你好运!
Your code looks fine. A somewhat similar example of it is given here:
http://www.codenewsgroups.net/aspnetwebcontrols/t5289-solution-radiobuttonlist-with-images.aspx[^]

I think you would need to check the image url and check out if it is correct. You can always try entering that url as address in your browser.

Good luck!


你好Nijboer,

我检查了我的代码.它与显示的完全一样.甚至我在浏览器中尝试过的图片网址,但都显示了图片.我不知道出什么问题了.你还能给我建议吗?

预先感谢..
Hello Nijboer,

I checked my code. Its exactly as it is shown. Even the image url i tried in the browser but its showing the image. I don''t know whats the problem. Can u suggest me anything else?

Thanks in advance..


尝试这种方式

Try this way

string imagefolder = "/images/";
DataSet ds ;
foreach(DataRow dr in ds.Tables[0].Rows)
{

 this.RadioButtonList1.Items.Add(new ListItem(String.Format("<img src='{0}'>", imagefolder + dr["ImageFile"].ToString()), dr["ImageID"].ToString()));

}



请发布您的查询/评论作为对答案的评论.请勿将其添加为答案.



Please post your queries/comments as comments to answers.Do not add it as answer.


这篇关于如何将图像添加到Radiobuttonlist.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆