API Questions on Kentico API.
Version 6.x > API > Images in Webpart View modes: 
User avatar
Member
Member
brendan-ignitedcoder - 10/16/2012 2:56:53 PM
   
Images in Webpart
Hi,

I have my web parts working well to retrieve data for Events/News which I then add to a custom datatable. I then bind this data table to a asp:Repeater... This dislay all of my data correctly and ordered the way I need it. I'm only missing one thing...

Heres how I build my table
DataTable dtEvents = new DataTable("Spotlight Data");
dtEvents.Columns.Add("Title", typeof(string));
dtEvents.Columns.Add("Date", typeof(DateTime));
dtEvents.Columns.Add("Summary", typeof(string));
//dtEvents.Columns.Add("Teaser", typeof(byte));

foreach (DataRow row in dsEvents.Tables[0].Rows)
{
dtEvents.Rows.Add(row["EventName"].ToString(),
System.Convert.ToDateTime(row["EventDate"]),
row["EventSummary"].ToString(),
Image call goes here to add to table);
}

I need to add the teaser image to it... so how do I call GetImage when I add a table row???

Thanks

Brendan

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 10/17/2012 8:24:17 AM
   
RE:Images in Webpart
Hi Brendan,

Why exactly do you want to store the image in your custom table this way? As I see they are already stored in the Events table. Can you give me the example?

I would recommend you to create custom tables via Kentico API - Managing custom table data and then use the Repeater WebPart (GetImage() method): Available web parts in Custom tables.

Best regards,
Martin Danko

User avatar
Member
Member
brendan-ignitedcoder - 10/17/2012 8:36:53 AM
   
RE:Images in Webpart
Hi Martin,

I've simply added the new fields to the Event and News document types.

Then I simply grab it from the Views....
QueryDataParameters parameters = new QueryDataParameters();
GeneralConnection cn = ConnectionHelper.GetConnection();
DataSet dsEvents = ConnectionHelper.ExecuteQuery("select top 2 * from View_CONTENT_Event_Joined order by EventDate", parameters, QueryTypeEnum.SQLQuery, true);
DataSet dsNews = ConnectionHelper.ExecuteQuery("select top 2 * from View_CONTENT_News_Joined order by NewsReleaseDate", parameters, QueryTypeEnum.SQLQuery, true);

I then bind the datatable to a standard asp:Repeater
<asp:Repeater runat="server" ID="SpotlightRepeater">
<ItemTemplate><li>
<img src="<%# DataBinder.Eval(Container, "DataItem.Teaser")%>" alt="" />
<h4><%# DataBinder.Eval(Container, "DataItem.Title")%></h4>
<p>
%# DataBinder.Eval(Container, "DataItem.Summary")%>
</p>
</li></ItemTemplate>
</asp:Repeater>

This works great, now I just need the path to show the images... I tried the following:
CMSAbstractTransformation imgHelper = new CMSAbstractTransformation();
string sImgPath = string.Empty;

foreach (DataRow row in dsEvents.Tables[0].Rows)
{
sImgPath = imgHelper.GetAttachmentUrl(row["EventTeaserImg"], row["NodeAliasPath"]);
dtEvents.Rows.Add(row["EventName"].ToString(), System.Convert.ToDateTime(row["EventDate"]), row["EventSummary"].ToString(),sImgPath);
}

Thanks
Brendan

User avatar
Kentico Customer Success
Kentico Customer Success
kentico_martind2 - 11/4/2012 8:14:22 AM
   
RE:Images in Webpart
Hi Brendan,

you should be able to use one of these macros:
IfEmpty(Eval("BlogTeaser"), "", GetImage("BlogTeaser"))
or
GetDocumentUrl(object nodeGuidColumn, object nodeAlias)

Best regards,
Martin Danko