[RESOLVED] Getting values from datagrid problem?
ny ideas how Ive broke this? :blush: It worked before but now I get this error
Quote:
[ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index]
VB Code:
Private Sub dgNewCarriageBuildSheets_UpdateCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgNewCarriageBuildSheets.UpdateCommand
'Declare variables
Dim txtGearMotor As TextBox
Dim txtRPM As TextBox
Dim dropHand As DropDownList
Dim txtPCB As TextBox
Dim txtMeggaTest As TextBox
Dim txtfTest As TextBox
Dim dropULTest As DropDownList
Dim txtsTest As TextBox
Dim calWEProd As Calendar
Dim dropModel As DropDownList
Dim txtSerialNo As TextBox
'Get the key value
[U] Main.objCarriageBuildSheet.PublicSerialNo = dgNewCarriageBuildSheets.DataKeys(e.Item.ItemIndex)[/U]
'Get other values from template columns
txtGearMotor = CType(e.Item.FindControl("txtMotorNo"), TextBox)
Re: Getting values from datagrid problem?
Did you set the datagrid's DataKeyField?
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:
<div id="divPrint"><asp:datagrid id="dgNewCarriageBuildSheets" runat="server" Width="100%" AllowPaging="True" PageSize="15"
AutoGenerateColumns="False" BorderColor="Control" BorderWidth="1pt">
<SelectedItemStyle Font-Size="X-Small"></SelectedItemStyle>
<EditItemStyle Font-Size="X-Small"></EditItemStyle>
<AlternatingItemStyle Font-Size="Small" BackColor="Menu"></AlternatingItemStyle>
<ItemStyle Font-Size="Small"></ItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" ForeColor="Black" BackColor="Menu"></HeaderStyle>
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="Lift Serial Number" ReadOnly="True" HeaderText="Serial No"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Motor Serial No">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Gearmotor Serial Number") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtMotorNo" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Gearmotor Serial Number") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="txtMotorNo" text="*" Runat="server" />
</EditItemTemplate>
</asp:TemplateColumn>
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:
'Bind grid to dataview
Private Sub BindGrid()
Main.objCarriageBuildSheet.GetBuilds()
Me.dgNewCarriageBuildSheets.DataSource = Main.objCarriageBuildSheet.vwCarriages
Me.dgNewCarriageBuildSheets.DataKeyField = "Lift Serial Number"
Me.dgNewCarriageBuildSheets.DataBind()
End Sub
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.