Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gridview update - no source code for the current position available 1

Status
Not open for further replies.

russland

Programmer
Jan 9, 2003
315
CH
Hi,

I got a GridView. I prepared UpdateCommands, run the page, click the edit button, the row falls into edit-mode, I change a value and click the standard update button/link... the system return with an error saying: no source code available for the current position. What am I missing in this update call?

Any hint is highly appreciated.



SQL UPDATE COMMAND
UpdateCommand="UPDATE [InvoiceElements] SET [InvoiceID] = @InvoiceID, [ElementTypeID] = @ElementTypeID, [Description] = @Description, [Cost] = @Cost, [ShareOfCostInPercentByRenter] = @ShareOfCostInPercentByRenter WHERE [ID] = @ID">

PARAMETERS
<UpdateParameters>
<asp:parameter Name="InvoiceID" Type="Int32" />
<asp:parameter Name="ElementTypeID" Type="Int32" />
<asp:parameter Name="Description" Type="String" />
<asp:parameter Name="Cost" Type="Decimal" />
<asp:parameter Name="ShareOfCostInPercentByRenter" Type="Decimal" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>

GRIDVIEW
<asp:GridView id="GridViewInvoiceElements" runat="server" ForeColor="#333333" DataSourceID="InvoiceElementsDS" AllowSorting="True" DataKeyNames="ID" AllowPaging="True" AutoGenerateColumns="False" GridLines="None" CellPadding="4">
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True"></FooterStyle>
<Columns>
<asp:BoundField DataField="InvoiceID" SortExpression="InvoiceID" HeaderText="RG-Nr."></asp:BoundField>
<asp:BoundField ReadOnly="True" DataField="ID" InsertVisible="False" SortExpression="ID" HeaderText="ID"></asp:BoundField>
<asp:TemplateField HeaderText="Kostenart" SortExpression="ElementType">
<EditItemTemplate>
<asp:DropDownList ID="ElementTypeID" runat="server" AppendDataBoundItems="false" DataSourceID="ElementTypesDS" DataTextField="ElementType" DataValueField="ID" EnableViewState="false" SelectedValue='<%# Bind("ElementTypeID") %>'></asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<% Eval("ElementType") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Description" SortExpression="Description" HeaderText="Beschrieb"></asp:BoundField>
<asp:BoundField DataField="Cost" SortExpression="Cost" HeaderText="Betrag"></asp:BoundField>
<asp:BoundField DataFormatString="{0:}%" DataField="ShareOfCostInPercentByRenter" SortExpression="ShareOfCostInPercentByRenter" HeaderText="Mieteranteil"></asp:BoundField>
<asp:CommandField ShowEditButton="True"></asp:CommandField>
<asp:CommandField ShowDeleteButton="True"></asp:CommandField>
</Columns>
</asp:GridView>
 
the system return with an error saying: no source code available for the current position
Was it Visual Studio saying this? If so, there may be a problem with the build. Sometimes this does happen so if you shut down VS, restart it and the do a Rebuild All, that may fix the problem.


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
Hmm, didn't help. Well, i have a german version of VS2005 so I wouldn't know what's the exact translation in English. However, the next error shown by VS is: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

yeah, I thought that's what I have done, didn't I?
 
And this is where the debugger stops - at the bound dropdownlist:

<asp:TemplateField HeaderText="Kostenart" SortExpression="ElementType">
<EditItemTemplate>
<asp:DropDownList ID="ElementTypeID" runat="server" AppendDataBoundItems="false" DataSourceID="ElementTypesDS" DataTextField="ElementType" DataValueField="ID" EnableViewState="false" SelectedValue='<%# Bind("ElementTypeID") %>'></asp:DropDownList>
0000009d mov dword ptr [ebp-5Ch],ebx
000000a0 mov edx,dword ptr ds:[022B2F0Ch]
000000a6 mov ecx,edi
000000a8 call FEF5A9A8
000000ad mov dword ptr [ebp-60h],eax
000000b0 call 71BA83E4
000000b5 mov dword ptr [ebp-64h],eax
000000b8 mov edx,dword ptr [ebp-64h]
000000bb mov ecx,dword ptr [ebp-60h]
000000be call 71BF3594
000000c3 mov dword ptr [ebp-68h],eax
000000c6 mov edx,dword ptr [ebp-68h]
000000c9 mov ecx,dword ptr [ebp-5Ch]
000000cc mov eax,dword ptr [ecx]
000000ce call dword ptr [eax+00000280h]
000000d4 nop
000000d5 nop
000000d6 nop
000000d7 lea esp,[ebp-0Ch]
000000da pop ebx
000000db pop esi
000000dc pop edi
000000dd pop ebp
000000de ret 4
 
Hmm, didn't help
So are you still getting the "no source code available for the current position" error?

However, the next error shown by VS is: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Does VS show where this error is occuring?


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
(Hmm, didn't help) yes, still the same error. When I click on OK the next error window occures: InvalidOperationException (the one I just posted in my last entry)

As you can see, it stops exactly at the Dropdownlist - it's probably because of the Bind("ElementTypeID").
--> Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.

But why? I have to bind the ElementTypeID in the EditItemTemplate otherwise we cannot tell what value is selected in the dropdownlist.
 
It works, if I remove SelectedValue='<%# Bind("ElementTypeID") %>' (of the DropDownList). Hmm, I'm totaly clueless about this "misbehaviour".
 
To set the value of the DropDownList, you should:

1) use the data bound event of the GridView
2) use the FindControl method to get a reference to the DropDownList
3) Get the relevant Item by using the Items.FindByValue method
4) Set the Item that was found to Selected="True"


____________________________________________________________

Need help finding an answer?

Try the Search Facility or read FAQ222-2244 on how to get better results.

 
CA8MSM, thanks or your help so far.

Do you have a clue why I cannot find the DropDownList with the FindControl? (J, I didn't know this is so complex for such a tiny task.)

DropDownList dl = ((DropDownList)this.GridViewInvoiceElements.FindControl("ElementTypeID"));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top