By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,868 Members | 1,974 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,868 IT Pros & Developers. It's quick & easy.

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

P: 1
Expand|Select|Wrap|Line Numbers
  1. <asp:Panel ID="pnlScrolls" runat="server" ScrollBars="vertical" Height="600px"> 
  2.                                         <asp:GridView ID="gvRegistList" ShowFooter="True" runat="server" 
  3.                                                 AutoGenerateColumns="False" 
  4.                                             DataKeyNames="CPR_NO" BorderColor="#999999" RowStyle-BorderStyle="Solid" 
  5.                                                 Width="800px" AllowSorting="True" 
  6.                                             RowStyle-BorderWidth="1px" Font-Names="Arial" Font-Size="Medium" 
  7.                                                 CellPadding="3" BackColor="White" BorderStyle="Solid" 
  8.                                             BorderWidth="1px" GridLines="Vertical" PageSize="20" AllowPaging="True" 
  9.                                                 onpageindexchanging="gvRegistList_PageIndexChanging" 
  10.                                             ForeColor="Black" en >
  11.                                             <AlternatingRowStyle BackColor="#CCCCCC" />
  12.                                             <Columns>
  13. <%--                                               <asp:ButtonField CommandName="Select" Text="Button" HeaderText="CPR No."
  14.                                                     DataTextField="CPR_NO" SortExpression="nUserID">
  15.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  16.                                                     <HeaderStyle CssClass="THStyle " HorizontalAlign="Left" />
  17.                                                 </asp:ButtonField>
  18.  
  19.                                                 <asp:boundfield datafield="name" headertext="Patient Name" readonly="true" />--%>
  20.                                                 <asp:TemplateField HeaderText="CPR No." >
  21.                                                     <ItemTemplate>
  22.                                                         <asp:Label ID="lblCpr" runat="server" Text='<%# Bind("CPR_NO") %>'></asp:Label>
  23.                                                     </ItemTemplate>
  24.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  25.                                                     <HeaderStyle CssClass="THStyle" HorizontalAlign="Left" />
  26.                                                 </asp:TemplateField>
  27.  
  28.                                                 <asp:TemplateField HeaderText="NAME" >
  29.                                                     <ItemTemplate>
  30.                                                         <asp:Label ID="lblpatname" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
  31.                                                         <%--<asp:Label ID="lblCpr" runat="server" Visible="false" Text='<%# Bind("CPR_NO") %>'></asp:Label>--%>
  32.                                                     </ItemTemplate>
  33.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  34.                                                     <HeaderStyle CssClass="THStyle" HorizontalAlign="Left" />
  35.                                                 </asp:TemplateField>
  36.                                                 <asp:TemplateField HeaderText="DATE" >
  37.                                                     <ItemTemplate>
  38.                                                         <asp:Label ID="lblDate" runat="server" Text='<%# Bind("DATE") %>'></asp:Label>
  39.                                                     </ItemTemplate>
  40.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  41.                                                     <HeaderStyle CssClass="THStyle" HorizontalAlign="Left" />
  42.                                                 </asp:TemplateField>
  43.                                                 <asp:TemplateField HeaderText="TIME" >
  44.                                                     <ItemTemplate>
  45.                                                         <asp:Label ID="lblTimeIn" runat="server" Text='<%# Bind("TIMEIN") %>'></asp:Label>
  46.                                                         <%--<asp:Label ID="lblTimeIn" runat="server" Text='<%if # Bind("TIME") %>'></asp:Label>--%>
  47.                                                         <%--<asp:Label ID="lbGender" runat="server" Text='<% if(#Eval("NTNAEVENT")='0' { 'Male' else 'Female' }%>'></asp:Label>--%>
  48.                                                     </ItemTemplate>
  49.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  50.                                                     <HeaderStyle CssClass="THStyle" HorizontalAlign="Left" />
  51.                                                 </asp:TemplateField>
  52.                                                 <asp:TemplateField HeaderText="NTNAEVENT" >
  53.                                                     <ItemTemplate>
  54.                                                         <asp:Label ID="lblTimeOut" runat="server" Text='<%# Bind("TIMEOUT") %>'></asp:Label>
  55.                                                     </ItemTemplate>
  56.                                                     <ItemStyle CssClass="TDStyleLT" HorizontalAlign="Left" />
  57.                                                     <HeaderStyle CssClass="THStyle" HorizontalAlign="Left" />
  58.                                                 </asp:TemplateField>
  59.  
  60.                                             </Columns>
  61.                                            <%-- <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White"/>--%>
  62.                                             <RowStyle BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" 
  63.                                                 Height="20px" />
  64.                                             <PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="Black"  />
  65.                                             <FooterStyle BackColor="#CCCCCC" />
  66.                                             <HeaderStyle BorderColor="#404040" BorderStyle="Solid" BorderWidth="2px" 
  67.                                                 Wrap="True" BackColor="Black" Font-Bold="True" ForeColor="White" />
  68.                                             <PagerSettings NextPageText="Next" PreviousPageText="Previous" Visible="true" />
  69.                                             <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
  70.                                             <SortedAscendingCellStyle BackColor="#F1F1F1" />
  71.                                             <SortedAscendingHeaderStyle BackColor="#808080" />
  72.                                             <SortedDescendingCellStyle BackColor="#CAC9C9" />
  73.                                             <SortedDescendingHeaderStyle BackColor="#383838" />
  74.                                         </asp:GridView>
  75.                                         </asp:Panel>
  76.  
  77.  
  78.  
  79.  protected void gvRegistList_PageIndexChanging(object sender, GridViewPageEventArgs e)
  80.         {
  81.             //if(gvRegistList.PageIndex != null)
  82.             //    {
  83.             //    //Use
  84.             gvRegistList.PageIndex = e.NewPageIndex;
  85.             DataList();
  86.             //    }
  87.         }
  88.  
  89.  
  90. public void DataList()
  91.         {
  92.             try
  93.             {
  94.                 //Label lblCprNo = (Label)
  95.                 string strFDay, strFMonth, strFYear, strTDay, strTMonth, strTYear, strFDate, strTDate;
  96.                 strFDay = dtpFDate.SelectedDate.ToString().Substring(0, 2);
  97.                 strFMonth = dtpFDate.SelectedDate.ToString().Substring(3, 2);
  98.                 strFYear = dtpFDate.SelectedDate.ToString().Substring(6, 4);
  99.                 strFDate = strFYear + "-" + strFMonth + "-" + strFDay;
  100.  
  101.                 strTDay = dtpTDate.SelectedDate.ToString().Substring(0, 2);
  102.                 strTMonth = dtpTDate.SelectedDate.ToString().Substring(3, 2);
  103.                 strTYear = dtpTDate.SelectedDate.ToString().Substring(6, 4);
  104.                 strTDate = strTYear + "-" + strTMonth + "-" + strTDay;
  105.  
  106.                 DataTable dtSearch = new DataTable("TABLE");
  107.  
  108.                 //dtSearch = attList.Attendance_List(dtpFDate.SelectedDate.ToString().Substring(0, 10), dtpTDate.SelectedDate.ToString().Substring(0, 10), txtCpr.Text.Trim());
  109.                 dtSearch = attList.Attendance_List(strFDate, strTDate, txtCpr.Text.Trim());
  110.  
  111.                 if (dtSearch.Rows.Count > 0)
  112.                 {
  113.                     //gvRegistList.Rows. = dtSearch.Rows.Count;
  114.                     gvRegistList.DataSource = GetEmptyDataTableRegList(dtSearch.Rows.Count);
  115.                     gvRegistList.DataBind();
  116.                     lblMsg.Text = "";
  117.                     for (int iCurow = 0; iCurow <= dtSearch.Rows.Count - 1; iCurow++)
  118.                     {
  119.                         if (dtSearch.Rows[iCurow]["DATE"].ToString().Trim() != InDate.ToString().Trim())
  120.                         {
  121.                             //string DataId = gvRegistList.Rows[this.gvRegistList.SelectedRows[0].Index].Cells["CPR_NO"].Value.ToString();
  122.  
  123.                             //((Label)gvRegistList.Rows[iCurow].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[iCurow]["CPR_NO"]) ? "" : dtSearch.Rows[iCurow]["CPR_NO"].ToString());
  124.                             //((Label)gvRegistList.Rows[iCurow].FindControl("lblpatname")).Text = (Convert.IsDBNull(dtSearch.Rows[iCurow]["NAME"]) ? "" : dtSearch.Rows[iCurow]["NAME"].ToString());
  125.                             //((Label)gvRegistList.Rows[iCurow].FindControl("lblDate")).Text = (Convert.IsDBNull(dtSearch.Rows[iCurow]["DATE"]) ? "" : dtSearch.Rows[iCurow]["DATE"].ToString());
  126.                             PrevTmIn = "";
  127.                             PrevTmOut = "";
  128.                             for (int jCurow = iCurow; jCurow < dtSearch.Rows.Count - 1 && dtSearch.Rows[iCurow]["DATE"].ToString().Trim() == dtSearch.Rows[jCurow]["DATE"].ToString().Trim(); jCurow++)
  129.                             {
  130.                                 //if (iCurow > intRow)
  131.                                 //{
  132.                                 //    iCurow = intRow + 1;
  133.                                 //}
  134.                                 if (dtSearch.Rows[jCurow]["NTNAEVENT"].ToString().Trim() == "0")// && dtSearch.Rows[iCurow]["DATE"].ToString().Trim() != PrevDate.ToString().Trim())  //"0" -- Time In
  135.                                 {
  136.  
  137.                                     if (PrevTmIn.ToString().Trim() == "")
  138.                                     {
  139.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["CPR_NO"]) ? "" : dtSearch.Rows[jCurow]["CPR_NO"].ToString());
  140.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblpatname")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["NAME"]) ? "" : dtSearch.Rows[jCurow]["NAME"].ToString());
  141.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblDate")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["DATE"]) ? "" : dtSearch.Rows[jCurow]["DATE"].ToString());
  142.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblTimeIn")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["TIMEIN"]) ? "" : dtSearch.Rows[jCurow]["TIMEIN"].ToString());
  143.                                     }
  144.                                     else if (dtSearch.Rows[jCurow]["TIMEIN"].ToString().Trim() != PrevTmIn.ToString().Trim())
  145.                                     {
  146.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["CPR_NO"]) ? "" : dtSearch.Rows[jCurow]["CPR_NO"].ToString());
  147.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblpatname")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["NAME"]) ? "" : dtSearch.Rows[jCurow]["NAME"].ToString());
  148.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblDate")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["DATE"]) ? "" : dtSearch.Rows[jCurow]["DATE"].ToString());
  149.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblTimeIn")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["TIMEIN"]) ? "" : dtSearch.Rows[jCurow]["TIMEIN"].ToString());
  150.                                     }
  151.                                     PrevTmIn = dtSearch.Rows[jCurow]["TIMEIN"].ToString().Trim();
  152.                                     //intRow = iCurow;
  153.                                 }
  154.                                 else if (dtSearch.Rows[jCurow]["NTNAEVENT"].ToString() == "1") //"1" -- Time Out
  155.                                 {
  156.                                     if (PrevTmOut.ToString().Trim() == "")
  157.                                     {
  158.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["CPR_NO"]) ? "" : dtSearch.Rows[jCurow]["CPR_NO"].ToString());
  159.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblpatname")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["NAME"]) ? "" : dtSearch.Rows[jCurow]["NAME"].ToString());
  160.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblDate")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["DATE"]) ? "" : dtSearch.Rows[jCurow]["DATE"].ToString());
  161.                                         ((Label)gvRegistList.Rows[iCurow].FindControl("lblTimeOut")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["TIMEOUT"]) ? "" : dtSearch.Rows[jCurow]["TIMEOUT"].ToString());
  162.                                     }
  163.                                     else if (dtSearch.Rows[jCurow]["TIMEOUT"].ToString().Trim() != PrevTmOut.ToString().Trim())
  164.                                     {
  165.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["CPR_NO"]) ? "" : dtSearch.Rows[jCurow]["CPR_NO"].ToString());
  166.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblpatname")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["NAME"]) ? "" : dtSearch.Rows[jCurow]["NAME"].ToString());
  167.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblDate")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["DATE"]) ? "" : dtSearch.Rows[jCurow]["DATE"].ToString());
  168.                                         ((Label)gvRegistList.Rows[iCurow + 1].FindControl("lblTimeOut")).Text = (Convert.IsDBNull(dtSearch.Rows[jCurow]["TIMEOUT"]) ? "" : dtSearch.Rows[jCurow]["TIMEOUT"].ToString());
  169.                                     }
  170.                                     PrevTmOut = dtSearch.Rows[jCurow]["TIMEOUT"].ToString().Trim();
  171.                                 }
  172.                                 PrevDate = dtSearch.Rows[jCurow]["DATE"].ToString();
  173.  
  174.                             }
  175.                             intRow = iCurow;
  176.                         }
  177.                         InDate = dtSearch.Rows[iCurow]["DATE"].ToString();
  178.  
  179.                         //((Label)gvRegistList.Rows[iCurow].FindControl("lblCpr")).Text = (Convert.IsDBNull(dtSearch.Rows[iCurow]["CPR_NO"]) ? "" : dtSearch.Rows[iCurow]["CPR_NO"].ToString());
  180.  
  181.                     }
  182.  
  183.                     //gvRegistList.DataSource = dtSearch;
  184.                     //gvRegistList.DataBind();
  185.  
  186.                 }
  187.                 else
  188.                 {
  189.                     lblMsg.Text = "No Records Available.";
  190.                     gvRegistList.DataSource = GetEmptyDataTableRegList(20);
  191.                     gvRegistList.DataBind();
  192.                 }
  193.             }
  194.             catch (Exception ex)
  195.             {
  196.                 lblMsg.Text = "Exception caught here: " + ex.ToString();
  197.             }
  198.         }
Jun 25 '13 #1
Share this Question
Share on Google+
1 Reply


Rabbit
Expert Mod 10K+
P: 12,370
Please use code tags when posting code.

It would help to know which line threw the error.
Jun 25 '13 #2

Post your reply

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