I am Reading some Sample Codes. The list has 5 columns: Title, Name, Address, Age and Picture. The type of information in Picture column is Hyperlink or Picture and Format Url as picture.
Then, Function Page_Load of WebPart's ascx file is like:
protected void Page_Load(object sender, EventArgs e) { SPWeb ospweb = SPContext.Current.Web; SPList oList = ospweb.Lists["ChangleXiaoqu"]; SPListItemCollection collItem = oList.GetItems("Name", "Age", "Address", "Pictrue"); Random random = new Random(); int RndItem = random.Next(1, collItem.Count + 1); SPListItem oItem = collItem[RndItem - 1]; //Please note this line this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode(oItem["Pictrue"].ToString().TrimEnd('?', '.', ',', ' ')); this.Name.Text = oItem["Name"].ToString(); this.Age.Text = SPEncode.HtmlEncode(oItem["Age"].ToString()); this.Address.Text = SPEncode.HtmlEncode(oItem["Address"].ToString()); }
There are errors on
this.ImgAuthor.ImageUrl = SPEncode.HtmlEncode(oItem["Pictrue"].ToString().TrimEnd('?', '.', ',', ' '));
If this line is commented, it will be ok!
So, How to get the url of a Hyperlink-or-Picture column to WebPart?