ASPX templates
Version 7.x > ASPX templates > How to bind data from custom table to query repeater (or sth more appropriate)? View modes: 
User avatar
Member
Member
izabelawlodarska-k2 - 11/13/2013 2:06:54 AM
   
How to bind data from custom table to query repeater (or sth more appropriate)?
I try to connect query repeater in kentico to data source (in this case it is custom table), unfortunately I have to do it in .aspx and code behind, not in webpart properties as always (I have to do custom development). I know that in CMS repeater I can do it in this way:
<cms:CMSRepeater ID="CMSRepeater1" runat="server" 
Path="/%"
ClassNames="CustomTable.MyTable"
EnablePaging="False"
StopProcessing="false"
SelectOnlyPublished="true"
>
<HeaderTemplate></HeaderTemplate>
<ItemTemplate><%# Eval("Description") %></ItemTemplate>
<FooterTemplate></FooterTemplate>
</cms:CMSRepeater>

Unfortunately it is custom table so this construction doesn't work, I tried to use queryrepeater, but it also doesn't work. Which control can I use to display data from custom table using my own template?
<cms:queryrepeater id="repItems" runat="server"  > 
<HeaderTemplate></HeaderTemplate>
<ItemTemplate><%# Eval("Description") %></ItemTemplate>
<FooterTemplate></FooterTemplate>
</cms:queryrepeater>

I tried also datasource="CustomTables.MyTable", datasourcename="customtabledatasource", customtable="My.Customtable" etc. but it also doesn't work...
Help ;-)

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/13/2013 2:28:35 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Hello,

Using Query repeater with data source makes no sense since you have to specify the SQL query for the query repeater - and the same thing is done basically by the data source.
You can connect the Datasource web parts to Basic repeater/datalist or standard repeater/datalist as described in the documentation. the idea is the same when using ASPX too. You will just specify the DataSource or DataSourceControl or DataSourceID parameters of the CMSRepeater control. You do not need to specify the class names since the data re already returned by the data source control.

Best regards,
Juraj Ondrus

User avatar
Member
Member
izabelawlodarska-k2 - 11/13/2013 4:17:08 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Thank you for fast response. Could you give me an example of using CMSrepeater with data from custom table: "customtable.MyCustomTable", please? I tried this one but it didn't display data... it just do nothing.

ascx control:
<cms:CMSRepeater ID="repLastInspirations" runat="server"  
DataSourceName="customtable.MyCustomTable"
EnablePaging="False"
StopProcessing="true"
SelectOnlyPublished="true"
>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<%# Eval("Description") %>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</cms:CMSRepeater>

code behind:
 protected void Page_Load(object sender, EventArgs e)
{
RepeaterDataBind();
}

public void RepeaterDataBind()
{
repLastInspirations.StopProcessing = false;
repLastInspirations.DataBind();
repLastInspirations.ReloadData(true);
}

What is wrong with it?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/13/2013 5:09:28 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Where and how is the datasource web part configured. Is the "customtable.MyCustomTable" ID of the datasource control? It looks more like custom table code name. Please, see the link to the documenation from my firs tpost to understand the idea of using data source web parts/controls.

Best regards,
Juraj Ondrus

User avatar
Member
Member
izabelawlodarska-k2 - 11/13/2013 5:37:51 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Ok, I can explain. :)
I would like to add my own .ascx control as a webpart to my site. It is not kentico webpart but my own custom control. I need to define my own template to display data because I need to put to every single row in table additional buttons and some logic to interact with users etc. so I cannot use a built-in webpart and its properties to show the data from custom table. I know that I can use built-in webpart + transformation, but I need something that is more customizable (i need a lot of code behind here!), so I would like to use CMSrepeater to show the data from table in my control.

I thought it is analogical to ClassName="CodeNameOfDocType" so I tried to use custom table code name.
customtable.MyCustomTable is custom table code name, is it possible to use it as datasource? I have read the documentation, and I still don't understand. I see that I made a mistake in data source tag, I should use it in that way:

DataSourceName="CustomTableDataSource"

but I still don't know how to put in .ascx the name of custom table that I want to show? Or how on the other way bind data fom my custom table to repeater. Or I should bind data in code behind? How to do it? Please, give mi example.

I found sth like CustomTable="customtable.MyCustomTable" here: http://devnet.kentico.com/docs/5_5/KenticoCMS_WebParts.pdf , but it is not supperted in CMSrepeater, and when I try to use "CustomTableRepeater" it doesn't exist. Wrong name? Please, help me.

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 11/13/2013 6:52:08 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Hello,

you need to use two controls one is the DATASOURCE - this one will pull the data from whereever you want. Then, you will connect this data source web part to the Repeater and the repeater will display the data. Just like the image on the documentation shows Datasource -> Repeater. you can use the general, default Data source web aprt for general usage or, you can also use the "Custom table data source" control which is designed for usage with custom tables:

<cms:CustomTableDataSource... and then use its Id to connect it to the repeater so the repeater has the data to display.

Best regards,
Juraj Ondrus

User avatar
Member
Member
izabelawlodarska-k2 - 11/13/2013 8:24:36 AM
   
RE:How to bind data from custom table to query repeater (or sth more appropriate)?
Thank you very much! It works :)