?
Solved

Assigning an Array to Repeater Control

Posted on 2009-04-17
5
Medium Priority
?
341 Views
Last Modified: 2013-12-17
In my project I am using a Repeater control.
The Repeater Control has a maximum of  only 4 Rows.
And these values are hardcoded not coming from any database.
How to add these values to Repeater Control Dynamically.
I tried assigning array to Repeater.
Its neither giving any error nor returning any rows in the Repeater.
Any help will be highly appreciated.
string[] strArray = new string[] { "Index1", "Index2", "Index3" };
        this.rptChartList.DataSource = strArray;
        this.rptChartList.DataBind();

Open in new window

0
Comment
Question by:ken_rgr
  • 3
5 Comments
 
LVL 13

Accepted Solution

by:
sm394 earned 1000 total points
ID: 24172474
in aspx

add
<ItemTemplate>
                        <%#Container.DataItem %>
</ItemTemplate>
0
 
LVL 14

Expert Comment

by:amar31282
ID: 24173096
Please use datatable instead of array as below.

Please Correct the letter case problems
datatable dt = new datatable();
DataRow dr = new DataRow();
dt.columns.add("index");
dr = dt.NewRow();
dr("index") = "index1";
dt.rows.add(dr);
dr = dt.newRow();
 
dr("index") = "index2";
dt.Rows.Add(dr);
 
.....
and so on.
 
and then
 
rpt.DataSource = dt;
rpt.DataBind();

Open in new window

0
 

Author Comment

by:ken_rgr
ID: 24185147
Hi Amar 31282

the line 5 , 9 giving me an error

dr("index") = "index1";

For the above  line I am getting the following error.
"dr is a Variable but used like a Method".

Could you tell me where exactly we are doing mistake.
Thanks
0
 
LVL 14

Assisted Solution

by:amar31282
amar31282 earned 1000 total points
ID: 24185453
oops you are using C#
use this one


datatable dt = new datatable();
DataRow dr = new DataRow();
dt.columns.add("index");
dr = dt.NewRow();
dr["index"] = "index1";
dt.rows.add(dr);
dr = dt.newRow();
 
dr["index"] = "index2";
dt.Rows.Add(dr);
 
.....
and so on.
 
and then
 
rpt.DataSource = dt;
rpt.DataBind();

Open in new window

0
 
LVL 14

Expert Comment

by:amar31282
ID: 24185461
sorry it was my mistake
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month14 days, 9 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question