Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 Referencing an error problem.

Author  Topic 

macupryk
Starting Member

9 Posts

Posted - 2004-05-23 : 00:16:20
<code>
Hi, I am trying to reference an array.
And populate a checkbox with the appropriate values.

From this:
static public string[] ReadingStr =
{
"Prefer not to say","Biography","Culture","Erotica","Fantasy","Fiction",
"Romance","Historic Romance","True Crime","Non Fiction","Magazines",
"Popular","Rare and hard to find","Science","Science Fiction",
"Self Help","Thrillers","Mysteries","Comics","Art","Computers and internet",
"Food and drink","Lifestyles","Health and family","Home and garden",
"Poetry","Nature","Travel"};

For example.

Instead I am populating with the values
:ReadingStr
MovieStr
and so on.

So I have to reference through ReadingStr

the values:
Prefer not to say
Biography
Culture
and so on.

static public string[] Interest_CheckBoxListStr =
{
"Reading_CheckBoxList", "Movie_CheckBoxList", "Pet_CheckBoxList", "Play_CheckBoxList", "Sport_CheckBoxList", "Cooking_CheckBoxList", "Culinary_CheckBoxList", "Food_CheckBoxList",
"Hobbies_CheckBoxList", "Music_CheckBoxList", "Dance_CheckBoxList", "NightLife_CheckBoxList", "HouseKeeping_CheckBoxList", "PerfectEvening_CheckBoxList"};

static public string[] AddStrToCheckBoxList=
{
"ReadingStr", "MovieStr", "PetStr", "PlayStr", "SportStr", "CookingStr", "CulinaryStr",
"FoodStr", "HobbiesStr", "MusicStr", "DanceStr", "NightLifeStr", "HouseKeepingStr",
"PerfectEveningStr"};



private void Fill_CheckBoxList()
{
for (int i = 0; i < Interest_CheckBoxListStr.Length; i++)
{
string CtrlName= Interest_CheckBoxListStr[i];
CheckBoxList MyList = (CheckBoxList)Page.FindControl(CtrlName);
// Populate all the checkboxes
for (int j = 0; j < AddStrToCheckBoxList.Length; j++)
{
MyList.Items.Add(new ListItem(AddStrToCheckBoxList[j], j.ToString()));
}
}
}
</code>
   

- Advertisement -