PDA

Click to See Complete Forum and Search --> : [RESOLVED] Identifier Out Of Scope


MadCatVB
Feb 8th, 2006, 04:55 AM
Hi all,


private void filterStringFromArray()
{
ArrayList temp = ((ArrayList)ViewState["FilterExpression"]);

string sPriority;

sPriority = ((ArrayList)temp[0])[0].ToString();
}


I have the above code and for some reason when i try to assign the value to the string sPriority the watch window shows the error message:

Identifier 'sPriority' Out of scope.

As far as i was aware there is nothing wrong with the code.

Does anyone have any ideas on whats happening here?

Many thanks in advance

Grant

mendhak
Feb 8th, 2006, 05:16 AM
Remove the first indexer.

sPriority = ((ArrayList)temp)[0].ToString();

MadCatVB
Feb 8th, 2006, 05:35 AM
Hi mendhak,

Thanks for the response.

The viewstate in this is example is an ArrayList or ArrayList's. The first indexer is there so that I can access the first element in the temp Arraylist, the second so that i can access the element in the arraylist within temp.

Does this make sense? It doesn't seem to work if i just remove the firs indexer, I still get the out of scope error.

Thanks

mendhak
Feb 8th, 2006, 05:39 AM
No it doesn't make sense, but nevertheless, can you post more code? I ran this in a simple trial on my machine and it worked fine.

MadCatVB
Feb 8th, 2006, 05:50 AM
Ok, it didn't make sense :)

Hopefully this should help:


ArrayList alFilterAll = new ArrayList(3);

//add an array list for each of the columns with filters
ArrayList alPriority = new ArrayList();
alPriority.Add("Test Value In alPriority, element 0");
ArrayList alOwner = new ArrayList();
ArrayList alStatus = new ArrayList();
alFilterAll.Add(alPriority);
alFilterAll.Add(alOwner);
alFilterAll.Add(alStatus);

ViewState.Add("FilterExpression", alFilterAll);

filterStringFromArray();


This code is called on the page load to initialise the arraylists in the viewstate. I have a datagrid with a number of dropdownlist's in the header. These drop down lists are so the user can select an entry and the grid will filter on the selected items.

I need to keep the values that have been selected so that i can build the Where clause when creating the dataset that the grid is bound to.

At present i have three columns that can be filtered on hence three arraylist elements. Within each element i have another arraylist. Within these array lists I'm going to store the values that the user has selected in the drop downlist that they want to filter the grid on.

The function in my previous post is the start of one that can read in the values in the arraylists and then build the SQL where clause.

I appreciate that this may not make much more sense but here goes anyway.

I'm open to suggestions of better ways to do this type of thing.

Cheers

Grant

mendhak
Feb 8th, 2006, 06:26 AM
Alright, still works for me. Where is all this taking place? Inside a sub?

My advice:
Since this is ASP.NET, I suggest you use TemplateColumns, with asp.net DDLs in the headertemplate so that you can track those changes and the viewstates are automatically maintained.

Please note: My advice is worth more than 2 cents.

MadCatVB
Feb 8th, 2006, 06:47 AM
Its inside a subprocedure that i'm doing this yes.

At present my datagrid does contain template columns with the DDL's in them. I'll have to read up on maintaining state within these columns. If i'm maintaining the state this way I still need some where to store previous filter selections and append them to the current one.

I have working code that passes in the filter expression to a datagrid attribute as a string, The reason i was wondering about using arraylists in the viewstate is that it will save on code compared with all the string processing I am doing at present.

Thanks for your help on this matter.

Grant