Click here to Skip to main content
15,900,816 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I m working on an web application which gives information of user which use specific mailing system
grid having details of user is bound to webpage at runtime.
i m using web service to bind datagrid to page at runtime
i m asked to add one more column to this grid with name "Unlock user" which contains a link.
if 'account lock status' value taken from database is "Y" then i need to show the "unlock link" in "Unlock Column" else show nothing.
i have bound the column to grid and I fulfilled above condition too
but my problem is the above program runs fine for some time
that is when i click unlock button the program works fine
when i do this for 3 or more time(not fixed) even for first time also i get following error
"Collapse<br />
Index was out of range. Must be non-negative and less than the size of the collection.<br />
Parameter name: index<br />

the exception goes and again when i try to load page again sometimes it shows above exception again and when i click F5 program runs
I m not understanding when i click F5 then exception goes although i dont do anything then why its coming and to remove this what should i do?

public void EnableDisableControls()
{ FCS.BLL.CommonBLLOps dynobj = new FCS.BLL.CommonBLLOps();
string remoteUrl =System.Configuration.ConfigurationManager.AppSettings["SessionManager"];

DisableControls();//when this function s called i get exception and the function is defined below


C#
public void DisableControls()
    {
        // Disable All Controls Not Required for View Only
        BtnAdd.Visible = false;
        FlexiGrid1.Items[7].Hide = true;//at this line i get exception
    }



and datagrid is

C#
try
        {
            for (Int16 rowitem = 0; rowitem <= ItemCapacity-1; rowitem++)
            {
                _griddisplayitems += "{ display: '" + Items[rowitem].DisplayName +
                                    "', name: '" + Items[rowitem].ColumnName +
                                    "', width: " + Items[rowitem].ColumnWidth.ToString() +
                                    ", sortable: " + Items[rowitem].AllowSorting.ToString().ToLower() +
                                    ", hide: " + Items[rowitem].Hide.ToString().ToLower() +
                                    ", align: '" + Items[rowitem].ColumnAlignment.ToString() + "' },";
                if (Items[rowitem].Searchable)
                    searchableitems += "{ display: '" + Items[rowitem].DisplayName +
                                        "', name: '" + Items[rowitem].ColumnName + "' },";
            }
            _griddisplayitems = _griddisplayitems.Substring(0, _griddisplayitems.Length - 1);
            if (searchableitems.Length > 0)
                searchableitems = searchableitems.Substring(0, searchableitems.Length - 1);

        }
Posted
Updated 7-Aug-11 21:51pm
v4

1 solution

If you are going to use numeric indexes, then you must check that the number of entries in the array is sufficient, or you will get this error.
Try using the name of the entry instead: If you still get the error, then you need to check that you have any data at all...
 
Share this answer
 
Comments
Member 8081020 8-Aug-11 3:38am    
sorry i dont know much but then too the program works fine for sometime and sometime gives this error can u tell me in what conditions such things happen
if indexing would have creating the problem then it should not work at all
but when i click F5 then exception goes and program runs
OriginalGriff 8-Aug-11 3:55am    
It depends on the data - I can only assume (because I can't read your HDD) that the data fed to the array is too short.
Look at your code above, if FlexiGrid1 is fed from _griddisplayitems then I note that there are only six items in the list...so items[7] would be out of range.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900