Link to home
Start Free TrialLog in
Avatar of ken_rgr
ken_rgr

asked on

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

ASKER CERTIFIED SOLUTION
Avatar of Faizan Sarwar
Faizan Sarwar
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

Avatar of ken_rgr
ken_rgr

ASKER

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
sorry it was my mistake