|
-
Feb 8th, 2006, 05:55 AM
#1
Thread Starter
Addicted Member
[RESOLVED] Identifier Out Of Scope
Hi all,
Code:
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
-
Feb 8th, 2006, 06:16 AM
#2
Re: Identifier Out Of Scope
Remove the first indexer.
sPriority = ((ArrayList)temp)[0].ToString();
-
Feb 8th, 2006, 06:35 AM
#3
Thread Starter
Addicted Member
Re: Identifier Out Of Scope
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
-
Feb 8th, 2006, 06:39 AM
#4
Re: Identifier Out Of Scope
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.
-
Feb 8th, 2006, 06:50 AM
#5
Thread Starter
Addicted Member
Re: Identifier Out Of Scope
Ok, it didn't make sense 
Hopefully this should help:
Code:
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
-
Feb 8th, 2006, 07:26 AM
#6
Re: Identifier Out Of Scope
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.
-
Feb 8th, 2006, 07:47 AM
#7
Thread Starter
Addicted Member
Re: Identifier Out Of Scope
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|