Portal Engine Questions on portal engine and web parts.
Version 6.x > Portal Engine > Using a BasicRepeater and SQLDataSource in a custom WebPart View modes: 
User avatar
Member
Member
CJB - 10/21/2011 9:45:29 AM
   
Using a BasicRepeater and SQLDataSource in a custom WebPart
Hi

I have created a custom WebPart that I want to use to display data from an external system. I am trying to use a BasicRepeater with a SQLDataSource.

I have created the WebPart and added cms:BasicRepeater and cms:SQLDataSource.

I have set the following:

string connection = ConfigurationManager.ConnectionStrings"MyConnectionString"].ConnectionString;

dataSource.ConnectionString = connection;
dataSource.QueryText = "SELECT * FROM MyTable";
dataSource.QueryType = QueryTypeEnum.SQLQuery;
dataSource.LoadData(true);

repeater.DataSource = dataSource.DataSource;
repeater.DataBind();

The query is being correctly performed on the database but the WebPart is not displaying any data.

Are there any code examples that will help me to get this working.

Thanks
Craig

User avatar
Member
Member
kentico_edwardh - 10/21/2011 12:56:21 PM
   
RE:Using a BasicRepeater and SQLDataSource in a custom WebPart
Hello Craig,


The most important properties of SQLDataSource web part that you will need to use are ConnectionString and QueryText.

The ConnectionString property specify the connection string for database connection. If both server name and connection string are empty, application connection string is used by default.

The QueryText property defines the text of the query which will provide the data.

If you need to mode information about this web part I would like to point you to the following section of WebParts documentation:
http://devnet.kentico.com/docs/5_5R2/webparts/KenticoCMS_WebParts.htm#_2fb2ba51-e7ae-4277-8d98-8d1c886659e8

Each viewer web part (Repeater, BasicRepeater, Datalist etc ) has property called Data source name in which you can specify the data source web part which provides data displayed by the viewer web part.

So you can bind one SQLDataSource web part to more repeaters by setting their Data source name property. However, repeaters will display the same content. So if you want repeaters to display different data, you need to associate each repeater with different SQLDataSource with different sql query.

You can also find some useful information about using datasource web parts in following section of Developer's guide:
http://devnet.kentico.com/docs/5_5r2/devguide/index.html?using_datasource_web_parts.htm

Best Regards,
Edward Hillard

User avatar
Member
Member
CJB - 10/24/2011 3:05:26 AM
   
RE:Using a BasicRepeater and SQLDataSource in a custom WebPart
Edward

Thanks you for the information. I think I have just found out why nothing was being displayed in the repeater. I had not set the ItemTemplate property of the BasicRepeater

Thanks
Craig

User avatar
Member
Member
andreas.hartgers-bureau.knaw - 10/17/2012 5:06:08 AM
   
RE:Using a BasicRepeater and SQLDataSource in a custom WebPart
i have the same problem.

what do you mean by: I had not set the ItemTemplate property of the BasicRepeater?

i can't find that anywhere.

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/17/2012 5:20:53 AM
   
RE:Using a BasicRepeater and SQLDataSource in a custom WebPart
Hi,

here you can find more information about basic repeater and item template.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
andreas.hartgers-bureau.knaw - 10/17/2012 5:27:26 AM
   
RE:Using a BasicRepeater and SQLDataSource in a custom WebPart
ok, i got it. i had to build a Transformation template.