hi there,
i've just downloaded the new 4.1-version which is fabulous but now i stuck with a problem:
i've created an inline control which should manipulate a newsletter-adress-list. so i've used the generic asp.net gridview. filtering, paging, updating and deleting worked fine but now i had to integrate a listbox in one cell to be updated.
first of course i've tried this in a seperat demo project but as soon as i want to convert it in an inlinecontrol it doesn't work (a webpart neither).
the gridview represents the table: kontakte (contacts), as soon as i klick on update the column: anrede (title) converts into a listbox presenting the choice oer titles like: male, female aso...
if i want the changes to be updated and click on the button, i get following error:
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
Source Error:
[No relevant source lines]
Source File: c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\promontamag\6c85709b\33cafe95\App_Web_w8puwbdu.4.cs Line: 0
Stack Trace:
[InvalidOperationException: Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.]
System.Web.UI.Page.GetDataItem() +2638766
ASP.cmsinlinecontrols_promontam_admin_kontakte_ascx.__DataBinding__control10(Object sender, EventArgs e) in c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\promontamag\6c85709b\33cafe95\App_Web_w8puwbdu.4.cs:0
System.Web.UI.Control.OnDataBinding(EventArgs e) +99
System.Web.UI.WebControls.ListControl.OnDataBinding(EventArgs e) +14
System.Web.UI.WebControls.ListControl.PerformSelect() +34
System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
System.Web.UI.WebControls.ListBox.LoadPostData(String postDataKey, NameValueCollection postCollection) +65
System.Web.UI.WebControls.ListBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +13
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +346
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1434
Version Information: Microsoft .NET Framework Version:2.0.50727.3082; ASP.NET Version:2.0.50727.3082
Here is the code i use:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="50"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="">
<ItemTemplate>
<asp:Button ID="btnDelete" Text="Löschen" runat="server" OnClientClick="return confirm('Soll dieser Datensatz wirklich gelöscht werden?');" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" ButtonType="Link" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:TemplateField HeaderText="anrede" SortExpression="anrede">
<EditItemTemplate>
<asp:ListBox ID="lbAnrede" runat="server" DataSourceID="SqlDataSource2"
Rows="1" SelectionMode="Single" SelectedValue='<%# Bind("anrede") %>'
DataTextField="bezeichnung" DataValueField="id" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("anrede") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="vorname" HeaderText="vorname" SortExpression="vorname" />
<asp:BoundField DataField="nachname" HeaderText="nachname" SortExpression="nachname" />
<asp:BoundField DataField="email" HeaderText="email" SortExpression="email" />
<asp:CheckBoxField DataField="newsletterabo" HeaderText="newsletterabo" SortExpression="newsletterabo" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"
DeleteCommand="DELETE FROM [kontakte] WHERE [id] = @id"
InsertCommand="INSERT INTO [kontakte] ([anrede], [vorname], [nachname], [email], [newsletterabo]) VALUES (@anrede, @vorname, @nachname, @email, @newsletterabo)"
SelectCommand="SELECT [id], [anrede], [vorname], [nachname], [email], [newsletterabo] FROM [kontakte]"
UpdateCommand="UPDATE [kontakte] SET [anrede] = @anrede, [vorname] = @vorname, [nachname] = @nachname, [email] = @email, [newsletterabo] = @newsletterabo WHERE [id] = @id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="anrede" Type="Int32" />
<asp:Parameter Name="vorname" Type="String" />
<asp:Parameter Name="nachname" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="newsletterabo" Type="Boolean" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="anrede" Type="Int32" />
<asp:Parameter Name="vorname" Type="String" />
<asp:Parameter Name="nachname" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="newsletterabo" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:CMSConnectionString %>"
SelectCommand="SELECT [id], [bezeichnung] FROM [anrede]">
</asp:SqlDataSource>
any suggestions?
thank you a lot!