2017-07-05 26 views
0

編集ボタンをクリックすると行rowdataboundイベントで範囲外の例外が発生しますが、データに関係なく9番目と10番目の項目のみどのページでも)。引数がグリッドビューの9番目と10番目の項目の範囲外

ここでエラーが発生します。

DropDownList DropDownList_QuantityType = (DropDownList)e.Row.Cells[e.Row.RowIndex].FindControl("DropDownList_QuantityType"); 

これはrowdataboundイベントです。

protected void GridView_BidItemTypeTables_RowDataBound(object sender, GridViewRowEventArgs e) 
    { 
     if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState & DataControlRowState.Edit) == DataControlRowState.Edit) 
     { 
      DropDownList DropDownList_QuantityType = (DropDownList)e.Row.Cells[e.Row.RowIndex].FindControl("DropDownList_QuantityType"); 
      DropDownList_QuantityType.SelectedValue = GridView_BidItemTypeTables.DataKeys[e.Row.RowIndex].Values[1].ToString(); 
      DropDownList DropDownList_FHWA = (DropDownList)e.Row.Cells[e.Row.RowIndex].FindControl("DropDownList_FHWA"); 
      DropDownList_FHWA.SelectedValue = GridView_BidItemTypeTables.DataKeys[e.Row.RowIndex].Values[2].ToString(); 
     } 
    } 

がPageSizeは10に設定されているので、[8]、[9]アイテムが範囲例外のうち引数であろう、なぜ私は理解していません。

PageSizeを8に変更しようとしましたが、8つの項目すべてが問題なく動作しました。 PageSizeを11に変更したとき、最後の3つの項目が最後の2の代わりに失敗しました。

ここはaspxページのビューです。

<asp:View ID="View_BidItemTypeTables" runat="server"> 
     <div> 
      <div style="width: 100%; overflow-x: scroll; overflow-y: auto;"> 
       <asp:GridView ID="GridView_BidItemTypeTables" runat="server" AutoGenerateColumns="false" EmptyDataText="No Records" DataKeyNames="GUID, QuantityTypeGuid,FHWA" AllowPaging="true" PageSize="10" 
        CssClass="gridview" Width="50%" BorderColor="Black" BorderWidth="1px" BorderStyle="Solid" OnRowCancelingEdit="GridView_BidItemTypeTables_RowCancelingEdit" OnRowEditing="GridView_BidItemTypeTables_RowEditing" OnRowUpdating="GridView_BidItemTypeTables_RowUpdating" OnRowDataBound="GridView_BidItemTypeTables_RowDataBound" OnPageIndexChanging="GridView_BidItemTypeTables_PageIndexChanging" OnRowCommand="GridView_BidItemTypeTables_RowCommand"> 
        <Columns> 
         <asp:TemplateField> 
          <ItemTemplate> 
           <asp:Button ID="Button_EditTypeTables" runat="server" CommandName="Edit" Text="Edit" Visible="true" CommandArgument="<%# Container.DataItemIndex %>" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:Button ID="Button_SaveTypeTables" runat="server" CommandName="Update" Text="Save" Visible="true" OnClick="Button_SaveTypeTables_Click" CausesValidation="true" ValidationGroup="ValidationFailed" /><asp:Button ID="Button_CancelTypeTables" runat="server" CommandName="Cancel" Text="Cancel" Visible="true" /> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Code"> 
          <ItemTemplate> 
           <asp:Label ID="Label_Code" Text='<%# Bind("Code") %>' runat="server" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox_Code" Text='<%# Bind("Code") %>' runat="server" /> 
           <asp:RequiredFieldValidator ID="RequiredFieldValidator_Code" runat="server" ErrorMessage="Code is Required." ControlToValidate="TextBox_Code" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification" SetFocusOnError="true">*</asp:RequiredFieldValidator> 
           <asp:CustomValidator runat="server" ID="CustomValidator_CodeGrid" ControlToValidate="TextBox_Code" ClientIDMode="Static" ValidationGroup = "ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxCodeValidatorBidItem_Grid" SetFocusOnError="true">*</asp:CustomValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Description"> 
          <ItemTemplate> 
           <asp:Label ID="Label_Description" Text='<%# Bind("Description") %>' runat="server" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox_Description" Text='<%# Bind("Description") %>' runat="server" /> 
           <asp:CustomValidator runat="server" ID="CustomValidator_DescriptionGrid" ControlToValidate="TextBox_Code" ClientIDMode="Static" ValidationGroup = "ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxDescriptionValidatorBidItem_Grid" SetFocusOnError="true">*</asp:CustomValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="QuantityType"> 
          <ItemTemplate><%# Eval("QuantityType.Code") %></ItemTemplate> 
          <EditItemTemplate> 
           <asp:DropDownList ID="DropDownList_QuantityType" AppendDataBoundItems="True" DataSourceID="ObjectDataSource_QuantityType" DataTextField="Code" DataValueField="Guid" runat="server"> 
           </asp:DropDownList> 
           <asp:RequiredFieldValidator ID="RequiredFieldValidator_QuantityType" runat="server" ErrorMessage="QuantityType is Required." ControlToValidate="DropDownList_QuantityType" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification" SetFocusOnError="true">*</asp:RequiredFieldValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="Unit"> 
          <ItemTemplate> 
           <asp:Label ID="Label_Unit" Text='<%# Bind("Unit") %>' runat="server" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox_Unit" Text='<%# Bind("Unit") %>' runat="server" /> 
           <asp:RequiredFieldValidator ID="RequiredFieldValidator_Unit" runat="server" ErrorMessage="Unit is Required." ControlToValidate="TextBox_Unit" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
           <asp:CustomValidator runat="server" ID="CustomValidator_UnitGrid" ControlToValidate="TextBox_Code" ClientIDMode="Static" ValidationGroup = "ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxUnitValidatorBidItem_Grid" SetFocusOnError="true">*</asp:CustomValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="UnitPrice"> 
          <ItemTemplate> 
           <asp:Label ID="Label_UnitPrice" Text='<%# Bind("UnitPrice") %>' runat="server" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:TextBox ID="TextBox_UnitPrice" Text='<%# Bind("UnitPrice") %>' runat="server" MaxLength="9"/> 
           <asp:RequiredFieldValidator ID="RequiredFieldValidator_UnitPrice" runat="server" ErrorMessage="Unit Price is Required." ControlToValidate="TextBox_UnitPrice" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
           <asp:RegularExpressionValidator ID="RegularExpressionValidator_UnitPrice" runat="server" CssClass="failureNotification" ErrorMessage="Unit Price is in incorrect format or exceeds (999999.99)." ControlToValidate="TextBox_UnitPrice" Display="Dynamic" ValidationGroup="ValidationFailed" ValidationExpression="^\d{0,6}(\.\d{1,2})?$" SetFocusOnError="true">*</asp:RegularExpressionValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="FHWA"> 
          <ItemTemplate> 
           <asp:Label ID="Label_FHWA" Text='<%# Bind("FHWA") %>' runat="server" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:DropDownList ID="DropDownList_FHWA" AppendDataBoundItems="True" runat="server"> 
            <asp:ListItem Value="" Selected="true">Select FHWA</asp:ListItem> 
            <asp:ListItem Value="Y">Y</asp:ListItem> 
            <asp:ListItem Value="N">N</asp:ListItem> 
           </asp:DropDownList><asp:RequiredFieldValidator ID="RequiredFieldValidator_FHWA" runat="server" ErrorMessage="FHWA is Required." ControlToValidate="DropDownList_FHWA" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
          </EditItemTemplate> 
         </asp:TemplateField> 
         <asp:TemplateField HeaderText="IsActive"> 
          <ItemTemplate> 
           <asp:CheckBox ID="CheckBox_IsActive" Checked='<%# Bind("IsActive") %>' runat="server" Enabled="False" /> 
          </ItemTemplate> 
          <EditItemTemplate> 
           <asp:CheckBox ID="CheckBox_IsActive" Checked='<%# Bind("IsActive") %>' runat="server" /> 
          </EditItemTemplate> 
         </asp:TemplateField> 
        </Columns> 
       </asp:GridView> 
      </div> 
      <br /> 
      <br /> 
      <asp:Panel ID="Panel_AddBidItemTypeTables" runat="server" Visible="false"> 
       <table width="35%"> 
        <tr> 
         <td>Code:</td> 
         <td> 
          <asp:TextBox ID="TextBox_CodeBidItemTypeTables" runat="server"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator_CodeBidItemTypeTables" runat="server" ErrorMessage="Code is Required." ControlToValidate="TextBox_CodeBidItemTypeTables" Display="Dynamic" ValidationGroup="ValidationFailed" Enabled="false" CssClass="failureNotification" SetFocusOnError="true">*</asp:RequiredFieldValidator> 
          <asp:CustomValidator runat="server" ID="CustomValidator_CodeBidItemTypeTables" ControlToValidate="TextBox_CodeBidItemTypeTables" ClientIDMode="Static" ValidationGroup="ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxCodeValidatorBidItem" SetFocusOnError="true">*</asp:CustomValidator> 
         </td> 
        </tr> 
        <tr> 
         <td>Description:</td> 
         <td> 
          <asp:TextBox ID="TextBox_DescriptionBidItemTypeTables" runat="server" ClientIDMode="Static"></asp:TextBox> 
          <asp:CustomValidator runat="server" ID="CustomValidator_DescriptionBidItemTypeTables" ControlToValidate="TextBox_DescriptionBidItemTypeTables" ClientIDMode="Static" ValidationGroup="ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxDescriptionValidatorBidItem" SetFocusOnError="true">*</asp:CustomValidator> 
         </td> 
        </tr> 
        <tr> 
         <td>Quantity Type:</td> 
         <td> 
          <asp:DropDownList ID="DropDownList_QuantityTypeBidItemTypeTables" AppendDataBoundItems="True" DataSourceID="ObjectDataSource_QuantityType" DataTextField="Code" DataValueField="Guid" runat="server"> 
           <asp:ListItem Value="" Selected="true">Select QuantityType</asp:ListItem> 
          </asp:DropDownList> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator_QuantityTypeBidItemTypeTables" runat="server" Enabled="false" ErrorMessage="Quantity Type is Required." ControlToValidate="DropDownList_QuantityTypeBidItemTypeTables" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification" SetFocusOnError="true">*</asp:RequiredFieldValidator> 
         </td> 
        </tr> 
        <tr> 
         <td>Unit:</td> 
         <td> 
          <asp:TextBox ID="TextBox_UnitBidItemTypeTables" runat="server"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator_UnitBidItemTypeTables" runat="server" ErrorMessage="Unit is Required." ControlToValidate="TextBox_UnitBidItemTypeTables" Display="Dynamic" ValidationGroup="ValidationFailed" Enabled="false" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
          <asp:CustomValidator runat="server" ID="CustomValidator_UnitBidItemTypeTables" ControlToValidate="TextBox_UnitBidItemTypeTables" ClientIDMode="Static" ValidationGroup="ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxUnitValidatorBidItem" SetFocusOnError="true">*</asp:CustomValidator> 
         </td> 
        </tr> 
        <tr> 
         <td>UnitPrice:</td> 
         <td> 
          <asp:TextBox ID="TextBox_UnitPriceBidItemTypeTables" runat="server" MaxLength="9"></asp:TextBox> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator_UnitPriceBidItemTypeTables" runat="server" ErrorMessage="Unit Price is Required." ControlToValidate="TextBox_UnitPriceBidItemTypeTables" Display="Dynamic" ValidationGroup="ValidationFailed" Enabled="false" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
          <asp:CustomValidator runat="server" ID="CustomValidator_UnitPriceBidItemTypeTables" ControlToValidate="TextBox_UnitPriceBidItemTypeTables" ClientIDMode="Static" ValidationGroup="ValidationFailed" Display="Dynamic" Enabled="true" CssClass="failureNotification" OnServerValidate="TextBoxUnitPriceValidatorBidItem" SetFocusOnError="true">*</asp:CustomValidator> 
         </td> 
        </tr> 
        <tr> 
         <td>FHWA:</td> 
         <td> 
          <asp:DropDownList ID="DropDownList_FHWABidItemTypeTables" AppendDataBoundItems="True" runat="server"> 
           <asp:ListItem Value="" Selected="true">Select FHWA</asp:ListItem> 
           <asp:ListItem Value="Y">Y</asp:ListItem> 
           <asp:ListItem Value="N">N</asp:ListItem> 
          </asp:DropDownList> 
          <asp:RequiredFieldValidator ID="RequiredFieldValidator_FHWABidItemTypeTables" runat="server" Enabled="false" ErrorMessage="FHWA is Required." ControlToValidate="DropDownList_FHWABidItemTypeTables" Display="Dynamic" ValidationGroup="ValidationFailed" CssClass="failureNotification">*</asp:RequiredFieldValidator> 
         </td> 
         <td> 
          <asp:Button ID="Button_AddBidItemTypeTables" runat="server" Text="Add" CausesValidation="true" ValidationGroup="ValidationFailed" OnClick="Button_AddBidItemTypeTables_Click" /> 
         </td> 
        </tr> 
       </table> 
      </asp:Panel> 
     </div> 
    </asp:View> 

誰もが以前同様の問題を経験しましたか?

+0

それを修正しました。ありがとうございました。 – Chris

答えて

0

e.Row.Cells[e.Row.RowIndex].FindControlの代わりにe.Row.FindControlを試してください。

関連する問題