473,847 Members | 1,707 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Index was out of range. Must be non-negative and less than the size of the collection

30 New Member
Respected Sir,
I am facing problem when i try to deploy my website on iis 7.0 on test page.
i have to display some .mht files on iframe in gridview and error looks like below,

Server Error in '/' Application.

Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Argument OutOfRangeExcep tion: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRa ngeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
System.Collecti ons.ArrayList.g et_Item(Int32 index) +7485640
System.Web.UI.W ebControls.Grid ViewRowCollecti on.get_Item(Int 32 index) +13
_Default.retriv efile(Int32 j) +977
_Default.Page_L oad(Object sender, EventArgs e) +598
System.Web.Util .CalliHelper.Ev entArgFunctionC aller(IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util .CalliEventHand lerDelegateProx y.Callback(Obje ct sender, EventArgs e) +41
System.Web.UI.C ontrol.OnLoad(E ventArgs e) +91
System.Web.UI.C ontrol.LoadRecu rsive() +74
System.Web.UI.P age.ProcessRequ estMain(Boolean includeStagesBe foreAsyncPoint, Boolean includeStagesAf terAsyncPoint) +2603
and the code that i used in retrivefile(int ) function is. Please check it..
Expand|Select|Wrap|Line Numbers
  1.  private void retrivefile(int j)
  2.     {
  4.             string medium = Request.QueryString["medium"];
  6.             ViewState["Question_selected"] = j;
  7.             string id = Session["uid"].ToString();
  8.             _repSource = new List<string>();
  9.             string url = Request.Url.ToString();
  10.             string[] url_array = url.Split('/');
  11.             string url1 = url_array[0] + "//" + url_array[2] + "/" + url_array[3];
  12.             SqlConnection filecon = new SqlConnection("Data Source="shekhar";initial catalog=walking;uid=sa;pwd=shekhar;");
  13.             filecon.Open();
  14.             SqlDataAdapter cmd = new SqlDataAdapter("select Serial_No from Question_Copy where Session_ID='" + id + "'", filecon);
  15.             DataSet ds = new DataSet();
  16.             cmd.Fill(ds);
  17.             int count = ds.Tables[0].Rows.Count;
  18.             string[] names = new string[count];
  19.             for (int i = 0; i < count; i++)
  20.             {
  21.                 names[i] = ds.Tables[0].Rows[i]["Serial_No"].ToString();
  23.             }
  24.             ViewState["Quest_Srno"] = names.ToArray();
  26.             j = selctquest(j);
  27.             string file1 = names[j] + ".mht";
  28.             if (medium == "English")
  29.             {
  30.                 _repSource.Insert(0, url1 + "/StaticHTM/" + file1);
  31.                 QuestionView1.DataSource = _repSource.ToArray();
  32.                 QuestionView1.DataBind();
  33.                 ViewState["Quest_Srno"] = names.ToArray();
  34.             }
  35.             if (medium == "Hindi")
  36.             {
  37.                 _repSource.Insert(0, url1 + "/New Folder/" + file1);
  38.                 QuestionView1.DataSource = _repSource.ToArray();
  39.                 QuestionView1.DataBind();
  40.                 ViewState["Quest_Srno"] = names.ToArray();
  42.             }
  43.             Label question_index = (Label)QuestionView1.Rows[0].FindControl("Label6");
  44.             question_index.Text = "Question &nbsp; " + (j + 1) + "&nbsp; of &nbsp;" + 50;
  45.             int total_quest = (int)ViewState["total_quest"];
  46.             totalbutton(total_quest);
  47.             Button2.Enabled = true;
  48.             Button4.Enabled = true;
  49.             Session["disable_submit"] = j;
  52.     }

please help me out where i am doing mistake, waiting for your reply.......... .
Jan 4 '10 #1
6 18717
115 New Member
The way i find best to solve this sort of issue is to put a breakpoint on your private void retrivefile then you can step through and check how many values are within your collections and then check that value against the value that you are searching for.

I'd be guessing but i would say it's either your _repsource or ds that do not contain the expected value.

put the break point in and have aa look also check your for loop

Hope this helps

Jan 4 '10 #2
shashi shekhar singh
30 New Member
Respected sir,
The above code is working properly in Visual Studio 2008 Debug mode but when i deployed this project on IIS 7.0 then it gives an error like above shown so please help me out.
Jan 6 '10 #3
9,735 Recognized Expert Moderator Expert
My guess would be on lines 26 and 27 in the above posted code:
Expand|Select|Wrap|Line Numbers
  1.   j = selctquest(j);
  2.   string file1 = names[j] + ".mht";
What is j?
Is j larger than the number of string elements in the names array?

Jan 6 '10 #4
shashi shekhar singh
30 New Member
thanx for your reply..
here ia m sending little section of gridview , i think it wll be helpfull to analyse my problem .
Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="QuestionView1" runat="server" AutoGenerateColumns="False" 
  2.                           BackColor="#A0C0CF" BorderColor="#660033" 
  3.                           BorderStyle="Outset" Height="226px" PageSize="1" Visible="False" 
  4.                           Width="127px" AllowPaging="False">
  5.                           <PagerSettings NextPageText="" PreviousPageText="" Visible="False" />
  6.                           <Columns>
  7.  <asp:TemplateField>
  8.                                   <ItemTemplate>
  9.                                       &nbsp;&nbsp;<asp:Label ID="Label6" runat="server" Font-Bold="True"></asp:Label>
  10.                                       <iframe ID="iframe1" runat="server" height="250" scrolling="auto" 
  11.                                           src="<%# Container.DataItem %>" style="background-color: #99CCFF" width="600">
  12.                                       </iframe>
  13.                                       <asp:RadioButtonList ID="RadioButtonList1" runat="server" BorderColor="#33CCFF" 
  14.                                           RepeatDirection="Horizontal" TextAlign="Left" Width="585px" Font-Bold="True" ForeColor="#FFCC00">
  15.                                           <asp:ListItem Value="1">Answer 1</asp:ListItem>
  16.                                           <asp:ListItem Value="2">Answer 2</asp:ListItem>
  17.                                           <asp:ListItem Value="3">Answer 3</asp:ListItem>
  18.                                           <asp:ListItem Value="4">Answer 4</asp:ListItem>
  19.                                       </asp:RadioButtonList>
  20.                                   </ItemTemplate>
  21.                               </asp:TemplateField>
  22. </Columns>
  23. </asp:Gridview>
and j=select(j) is a function which checks to know that any file have been accessed or not. i am sending you this function.
Expand|Select|Wrap|Line Numbers
  1. private int selctquest(int i)
  2. {
  4.     string[] quest_id = (string[])ViewState["Quest_Srno"];
  5.     //_srno = new List<string>();
  6.     if (i >= quest_id.Length)
  7.     {
  8.         blank_file();
  9.         i = i + 1;
  10.     }
  11.     else
  12.     {
  15.     string tablename = (string)Session["uid"];
  16.     SqlConnection con = new SqlConnection("Data Source=Server;initial catalog=database;uid=sa;pwd=");
  17.     con.Open();
  19.     SqlCommand cmd1 = new SqlCommand("select Count(*) from "+tablename+ "", con);
  20.     SqlDataReader reader = cmd1.ExecuteReader();
  21.     while (reader.Read())
  22.     {
  23.         int count = Convert.ToInt32(reader[0].ToString());
  24.         for (int j = 0; j <= count; j++)
  25.         {
  27.             SqlConnection con1 = new SqlConnection("Data Source="Server";initial catalog=database;uid=sa;pwd=");
  28.             con1.Open();
  30.             string sql = "select Q_ID from " + tablename + " ";
  31.             SqlCommand cmd = new SqlCommand(sql, con1);
  33.             SqlDataReader dr = cmd.ExecuteReader();
  35.             while (dr.Read())
  36.             {
  37.                 if (i > quest_id.Length-1)
  38.                 {
  39.                     i = i + 1;
  40.                     break;
  42.                 }
  43.                 string matchquest = quest_id[i];
  44.                 int match_item = Convert.ToInt32(matchquest.ToString());
  45.                 if (match_item == Convert.ToInt32(dr[0].ToString()))
  46.                 {
  49.                     i = i + 1;
  51.                 }
  53.             }
  54.             con1.Close();
  55.             }
  56.         }
  57.     con.Close();
  58.     }
  59.     return i;
  60. }
Jan 7 '10 #5
shashi shekhar singh
30 New Member
Thanx a lot for your help , i heave solved my problem.

but another problem occurs , when i try to access the files from the browser directly without going to login page on iis 7.0 then files are shown , Do you have any idea to restrict these files directly from the browser, i want to access these files only viewable on my test page in iframe and nothing anywhere else.
is it possible by adding manged handler in iis 7.0. if you have any other idea then please help me out.. i do'nt want to encrypt these all files or by adding some sripts to the every file(.mht) to embed in test.aspx page. please help me out it's urgent for me...i am waiting for you reply.....
from ..
shashi shekhar singh
Jan 8 '10 #6
9,735 Recognized Expert Moderator Expert
I'm glad you solved your problem. Please do not post post new questions in the same thread as your old question. Please post new questions in a new thread.

You should probably research Forms Authentication. This will let you restrict access to resources that are not meant for the public eye.

Jan 8 '10 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

by: skura | last post by:
I am trying to understand how the data in sql server is stored and also regarding fill factor and page splitting. 1) My first question what is the difference between Index pages and Data pages. and how are they different for clustered and non clustered indexes and heap tables. 2) What is the relation between index and data pages.
by: Anita | last post by:
Hi All, I have a table with an index. It contains column a to column m. There are two queries that often run : Query 1: select * from tb where a = '01' and b = '51' Query 2: select * from tb where a = '01' and b = '51' and c = 'yy' and d = 'zz' If I must create only one index and (a+b) may contains duplicate values. Which ones of the
by: Toni | last post by:
Hello, Is it possible that the z-index property for an iframe doesn't work when the SRC attribute is linked to a non html document? (i.e. a pdf document) That is what I am experiencing. I have a dropdown menu and an iframe and I want the menu always to be displayed above any object in the page. When the iframe is empty or it has an html page within, I can achieve this by setting the z-index property in the menu(div) higher
by: ES Kim | last post by:
"A Book on C" explains a technique to use an arbitrary array index range. int* p = malloc(sizeof(int) * 10) - 1; This way, the allocated array can be accessed with index range 1 ~ 10, not 0 ~ 9. You cannot use p, of course, and the memory should be released with free(p + 1). It worked with gcc and MSVC, but I'm not sure if it makes sense to take the address before the initial element of an array. Does anyone have any definite answer?
by: sam | last post by:
hey everybody, this is my first time posting here. i'm pretty new to python and programming in general (as you'll soon work out for yourselves...) i'm trying to code a version of a selection sort and the heart of the code is as follows (no_lines is simply the number of items to be sorted, read out of an input file): for j in range(0, no_lines):
by: hastha23 | last post by:
Dear friends, Any body tell me what is the difference between unique index and non unique index? I want briefly explantation.. Expecting your replies.. Hastha23
by: muzu1232004 | last post by:
If I have a table t1 with a column a as follows A 1 1 1 1 1 1 1
by: ferlarroca | last post by:
Hi, I am trying to copy a range below another one...... I have defined two ranges as follow: Dim r1 As Range Dim r2 As Range Set r1 = Sheets("Old Index").Range("A9:A200, H9:H200, K9:K200") Set r2 = Sheets("New Index").Range("A9:A200, H9:H200, K9:K200") I first copy the first range into another sheet by doing this:
by: Steffen Stellwag | last post by:
Truely is often better to scan a table in full passing by an index , but if you can force the optimizer to use an index via a hint for testing and comparing the results. But the index in the above example is not used , because the hint is malformed, if tables in a Select statment are named by aliases you have to specify the alias name in the hint statment , not the table name /*+ INDEX (ICWOIMP PK_ICWOIMP) */ change to /*+ INDEX (A...
by: vivek samantray | last post by:
I have a query.When i try to create a index on one of the table the index gets created but when i take the output it stuill shows "TABLE ACCESS FULL" Please see below what i did QUERY ====== SELECT b.DPT_EVNT_ID, b.DPT_ENTITY_ID, a.EDD_DT, b.DPT_DPT_ID, b.OU_ID,
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.