Assigning an Array to Repeater Control

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

ken_rgrAsked:
Who is Participating?
 
sm394Commented:
in aspx

add
<ItemTemplate>
                        <%#Container.DataItem %>
</ItemTemplate>
0
 
amar31282Commented:
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
 
ken_rgrAuthor Commented:
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
 
amar31282Commented:
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
 
amar31282Commented:
sorry it was my mistake
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.