Results 1 to 5 of 5

Thread: [RESOLVED] Getting values from datagrid problem?

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [RESOLVED] Getting values from datagrid problem?

    ny ideas how Ive broke this? It worked before but now I get this error
    [ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index]
    VB Code:
    1. Private Sub dgNewCarriageBuildSheets_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgNewCarriageBuildSheets.UpdateCommand
    2.         'Declare variables
    3.         Dim txtGearMotor As TextBox
    4.         Dim txtRPM As TextBox
    5.         Dim dropHand As DropDownList
    6.         Dim txtPCB As TextBox
    7.         Dim txtMeggaTest As TextBox
    8.         Dim txtfTest As TextBox
    9.         Dim dropULTest As DropDownList
    10.         Dim txtsTest As TextBox
    11.         Dim calWEProd As Calendar
    12.         Dim dropModel As DropDownList
    13.         Dim txtSerialNo As TextBox
    14.         'Get the key value
    15. [U]        Main.objCarriageBuildSheet.PublicSerialNo = dgNewCarriageBuildSheets.DataKeys(e.Item.ItemIndex)[/U]
    16.  
    17.         'Get other values from template columns
    18.  
    19.         txtGearMotor = CType(e.Item.FindControl("txtMotorNo"), TextBox)

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Getting values from datagrid problem?

    Did you set the datagrid's DataKeyField?

  3. #3

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: Getting values from datagrid problem?

    TBH Mendhak It's friday, some annoying woman opposite me wont shutup gossiping and my heads about to expode and now stuffs suddenly going wrong all these things have lead to me forgetting what the bloody data key even is.

    I must of had one once when it worked, perhaps i have deleted it later in the project should it be somewhere around here?

    VB Code:
    1. <div id="divPrint"><asp:datagrid id="dgNewCarriageBuildSheets" runat="server" Width="100%" AllowPaging="True" PageSize="15"
    2.                                     AutoGenerateColumns="False" BorderColor="Control" BorderWidth="1pt">
    3.                                     <SelectedItemStyle Font-Size="X-Small"></SelectedItemStyle>
    4.                                     <EditItemStyle Font-Size="X-Small"></EditItemStyle>
    5.                                     <AlternatingItemStyle Font-Size="Small" BackColor="Menu"></AlternatingItemStyle>
    6.                                     <ItemStyle Font-Size="Small"></ItemStyle>
    7.                                     <HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="Black" BackColor="Menu"></HeaderStyle>
    8.                                     <Columns>
    9.                                         <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
    10.                                         <asp:BoundColumn DataField="Lift Serial Number" ReadOnly="True" HeaderText="Serial No"></asp:BoundColumn>
    11.                                         <asp:TemplateColumn HeaderText="Motor Serial No">
    12.                                             <ItemTemplate>
    13.                                                 <asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Gearmotor Serial Number") %>'>
    14.                                                 </asp:Label>
    15.                                             </ItemTemplate>
    16.                                             <EditItemTemplate>
    17.                                                 <asp:TextBox id="txtMotorNo" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Gearmotor Serial Number") %>'>
    18.                                                 </asp:TextBox>
    19.                                                 <asp:RequiredFieldValidator ControlToValidate="txtMotorNo" text="*" Runat="server" />
    20.                                             </EditItemTemplate>
    21.                                         </asp:TemplateColumn>

  4. #4

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Re: [RESOLVED] Getting values from datagrid problem?

    Thanks Mendhak, after a crafty smoke sanity was restored and your tip off I realised the error of my ways, I must of deleted that line of code when attempting to neaten up my code earlier in the week.

    VB Code:
    1. 'Bind grid to dataview  
    2.     Private Sub BindGrid()
    3.         Main.objCarriageBuildSheet.GetBuilds()
    4.         Me.dgNewCarriageBuildSheets.DataSource = Main.objCarriageBuildSheet.vwCarriages
    5.         Me.dgNewCarriageBuildSheets.DataKeyField = "Lift Serial Number"
    6.         Me.dgNewCarriageBuildSheets.DataBind()
    7.  
    8.     End Sub

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: [RESOLVED] Getting values from datagrid problem?

    You think you've got it bad? I've been listening to two of my coworkers talk about 'Celebrity Big Brother' for the past 5 hours. FIVE hours.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width