数组项超出范围... [英] array item out of bound...

查看:81
本文介绍了数组项超出范围...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...
我在数组上遇到了错误,但是我计算了行和列的数量,但是仍然有一些问题...我正在发送代码,请给我一些解决的建议...

Hi...
i got error on array out of bound but i count the rows and columns but still having some problem...I am sending my code please give me some solving suggestion...

<div>
    <table border="0" cellpadding="0"  cellspacing="0"  width="100%">
        <tr>
            <td align="left" valign="top">
                <asp:label ID="lblName" Visible="false"  CssClass="lblBoldback" runat="server"></asp:label>
                &nbsp;&nbsp;&nbsp;
                <asp:label ID="lblRole" Visible="false" CssClass="lblBoldback" runat="server"></asp:label>
            </td>
        </tr>
        <tr>
            <td align="left" valign="top" >
                <asp:label ID="lblNoRecordFound" Visible="false" runat="server"></asp:label>
            </td>
        </tr>
        <tr>
            <td >
                 <asp:GridView ID="grdAdminInitiate" Visible="false"  BorderColor="AliceBlue" runat="server" CellPadding="4" Font-Names="verdana" Font-Size="Small"   ForeColor="#333333" GridLines="Horizontal"

                         Width="100%"  AutoGenerateColumns="False" AllowPaging="True" OnPageIndexChanging="grdAdminInitiate_PageIndexChanging">
                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                        <RowStyle BackColor="#f2f9ff" ForeColor="#333333" />
                        <EditRowStyle BackColor="#999999" />
                        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                        <HeaderStyle BackColor="#6699cc" Font-Bold="True" ForeColor="White" />
                        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                        <Columns>
                            <asp:BoundField DataField="emp_code" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Emp Code"/>
                            <asp:BoundField DataField="emp_name" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Name"/>
                            <asp:BoundField DataField="emp_designation" ItemStyle-HorizontalAlign ="Left"  Visible="true" HeaderStyle-HorizontalAlign="Left"  HeaderText="Designation"/>
                            <asp:BoundField DataField="grade" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Grade"/>
                            <asp:BoundField DataField="mail_sendto" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="eMail To" />
                            <asp:BoundField DataField="status" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Status"/>
                            <asp:BoundField DataField="appraiser_empcode" Visible="false"  ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Appraiser Emp Code" />
                            <asp:BoundField DataField="appraiser_name"   Visible="false" ItemStyle-HorizontalAlign ="Left" HeaderStyle-HorizontalAlign="Left"  HeaderText="Appraiser Name" />
                            <asp:TemplateField HeaderText="Initiate" ItemStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign ="Left">

                                <ItemTemplate>

                                        <asp:CheckBox ID="chkInitiate" AutoPostBack="true"  runat="server" />

                                 </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Freeze" ItemStyle-VerticalAlign="Top" ItemStyle-HorizontalAlign ="Left">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="chkFreeze" runat="server" />
                                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <PagerSettings PreviousPageText="Previous"  NextPageText="Next" FirstPageText="First" LastPageText="Last"/>
                 </asp:GridView>
            </td>
        </tr>
        <tr>
            <td align="right" valign="top">
                <asp:Button ID="btnInitiate" Visible="false"  runat="server" Text="Apply"  onclick="btnInitiate_Click"

                 BackColor="#47b5b5" BorderColor="#47b5b5" BorderStyle="None" ForeColor="White" Width="64px"/>
            </td>
        </tr>
    </table>
    </div>









/////////////////////////////////////////
protected void Page_Load(object sender, EventArgs e)
   {
       HtmlLink cssLink = new HtmlLink();
       cssLink.Href = "MedicalApp.css";
       cssLink.Attributes.Add("rel", "stylesheet");
       cssLink.Attributes.Add("type", "text/css");
       Header.Controls.Add(cssLink);

       string sCompany  = "";
       string sLocation = "";
       string sEmpCode  = "";
       grdAdminInitiate.RowDataBound += new GridViewRowEventHandler(grdAdminInitiate_RowDataBound);
       Library lib = new Library();
       DataTable dtAdminInitiate = null;

       if (!IsPostBack)
       {
           if (Request.QueryString["comcode"] != null && Request.QueryString["comcode"].ToString() != "")
           {

               if (Request.QueryString["empcode"] != null && Request.QueryString["empcode"].ToString() != "")
               {
                   if (Request.QueryString["comcode"].ToString() == "HDP")
                   {
                       int iFlag = lib.SetCompanyCode("mehtascl", "rnv", "4", 1);
                       sCompany = "HDP";
                       sLocation = "RNF";
                   }


                   sEmpCode = Request.QueryString["empcode"].ToString();
                   DataTable dtMedicalDetail = lib.getMedicalUserDetail(sCompany, sLocation, sEmpCode);

                   if (dtMedicalDetail != null)
                   {
                       if (dtMedicalDetail.Rows.Count > 0)
                       {
                           if (dtMedicalDetail.Rows[0].ItemArray[18] != null && dtMedicalDetail.Rows[0].ItemArray[18].ToString() != "")
                           {
                               string sAppRole = Convert.ToString(dtMedicalDetail.Rows[0].ItemArray[18]);
                               if (sAppRole.CompareTo("Admin") == 1)
                               {
                                   string sEmpShortNameAdmin = "";
                                   DataTable dtName = lib.getShortUserName(sCompany, Convert.ToString(sEmpCode));
                                   if (dtName.Rows.Count > 0)
                                   {
                                       string fname = Convert.ToString(dtName.Rows[0].ItemArray[0]);
                                       string mname = Convert.ToString(dtName.Rows[0].ItemArray[1]);
                                       string lname = Convert.ToString(dtName.Rows[0].ItemArray[2]);

                                       sEmpShortNameAdmin = fname + " " + mname + " " + lname;
                                   }
                                   lblName.Visible = true;

                                   lblName.Text = "Welcome : " + sEmpShortNameAdmin +" ,";
                                   lblRole.Visible = true;
                                   lblRole.Text = "Role : " + sAppRole.Trim();
                                   grdAdminInitiate.Visible = true;
                                   btnInitiate.Visible = true;
                                   dtAdminInitiate = lib.AdminInitiateApplication(sCompany, sLocation);
                               }
                               else
                               {
                                   lblName.Visible = false;
                                   lblRole.Visible = false;
                                   grdAdminInitiate.Visible = false;
                                   btnInitiate.Visible = false;
                               }
                           }
                       }
                   }


               }
           }


           if (dtAdminInitiate != null)
           {
               if (dtAdminInitiate.Rows.Count > 0)
               {
                   grdAdminInitiate.DataSource = dtAdminInitiate;
                   grdAdminInitiate.DataBind();

               }
               else
               {
                   lblName.Visible = false;
                   lblRole.Visible = false;
                   grdAdminInitiate.Visible = false;
                   btnInitiate.Visible = false;
                   lblNoRecordFound.CssClass = "Fail";
                   lblNoRecordFound.Text = "No record found";
               }
           }
       }
}



请帮助我....



PLEASE HELP ME OUT....

推荐答案

这是一个很大的代码,能否请您告诉我们确切的位置以及何时出现错误. :sigh:
This is a big code, can you please tell us exactly where and when you are getting error. :sigh:


请提及发生此错误的代码行.
Please mention the line of code where you get this error.


avijit1112010写道:
avijit1112010 wrote:

字符串mname = Convert.ToString(dtName.Rows [0] .ItemArray [1]);
字符串lname = Convert.ToString(dtName.Rows [0] .ItemArray [2]);

string mname = Convert.ToString(dtName.Rows[0].ItemArray[1]);
string lname = Convert.ToString(dtName.Rows[0].ItemArray[2]);


这看起来可能是例外的地方.

要基于带数字索引的ItemArray进行编码是不好的,请将其放在一边.每当您使用它时,请确保您拥有该权利并且不为null.

Check for null before accessing the ItemArray''s data.


This looks like a possible place for the exception.

To code based on ItemArray indexed with numbers are not good, keeping that aside.. whenever you are using it, make sure you have that right and is not null.

Check for null before accessing the ItemArray''s data.


这篇关于数组项超出范围...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆