I really need help on this, because I have no clue. I keep getting the following Error message when I try to update the fields in the mxdatagrid:
"The update command cannot be generated. In order to generate an update command, the DataKeyField must be set, AutoGenerateColumns must be true, and AutoGenerateExcludeFields cannot be used.
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.Web.HttpException: The update command cannot be generated. In order to generate an update command, the DataKeyField must be set, AutoGenerateColumns must be true, and AutoGenerateExcludeFields cannot be used.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): The update command cannot be generated. In order to generate an update command, the DataKeyField must be set, AutoGenerateColumns must be true, and AutoGenerateExcludeFields cannot be used.]
Microsoft.Matrix.Framework.Web.UI.MxDataGrid.OnUpd ateCommand(MxDataGridUpdateEventArgs e) +1010
Microsoft.Matrix.Framework.Web.UI.MxDataGrid.OnBub bleEvent(Object source, EventArgs e) +553
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
Microsoft.Matrix.Framework.Web.UI.MxDataGridItem.O nBubbleEvent(Object source, EventArgs e) +86
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +26
System.Web.UI.WebControls.Button.OnCommand(Command EventArgs e) +95
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +115
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1263"
************************************************** ******************
The code that I used is below:
<%@ Page Language="
VB" Strict="False" %>
<%@ Register TagPrefix="wmx" Namespace="Microsoft.Matrix.Framework.Web.UI" Assembly="Microsoft.Matrix.Framework, Version=0.6.0.0, Culture=neutral, PublicKeyToken=6f763c9966660626" %>
<script runat="server">
' Insert page code here
'
Sub MxDataGrid1_EditCommand(sender As Object, e As MxDataGridCommandEventArgs)
MxDAtaGrid1.EditItemIndex = e.Item.Itemindex
End Sub
Sub MxDataGrid1_BeforeUpdate(sender As Object, e As MxDataGridUpdateEventArgs)
e.NewVAlues.Add("@Title", CType(e.Item.Cells(2).Controls(0), TextBox).Text)
e.NewVAlues.Add("@ReleaseDate", CType(e.Item.Cells(3).Controls(0), TextBox).Text)
e.NewVAlues.Add("@Notes", CType(e.Item.Cells(4).Controls(0), TextBox).Text)
e.NewVAlues.Add("@Label", CType(e.Item.Cells(5).Controls(0), TextBox).Text)
e.NewVAlues.Add("@CoverImageURL", CType(e.Item.Cells(1).Controls(1), TextBox).Text)
e.NewVAlues.Add("@DiscID", MxDataGrid1.DataSource.DataSource.Tables(0).Rows(e .Item.DataSetIndex)(0))
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<wmx:SqlDataSourceControl id="SqlDataSourceControl1" runat="server" UpdateCommand="" SelectCommand="SELECT * FROM [Discs]" ConnectionString="server='(local)\NetSDK'; trusted_connection=true; database='CAM'" DeleteCommand=""></wmx:SqlDataSourceControl>
<wmx:MxDataGrid id="MxDataGrid1" onbeforeupdate="MxDataGrid1_BeforeUpdate" runat="server" OnEditCommand="MxDataGrid1_EditCommand" DataSourceControlID="SqlDataSourceControl1" BorderColor="#CCCCCC" AllowSorting="True" DataMember="Discs" AllowPaging="True" BackColor="White" CellPadding="3" DataKeyField="DiscID" BorderWidth="1px" BorderStyle="None" AutoGenerateFields="False">
<SelectedItemStyle font-bold="True" forecolor="White" backcolor="#669999"></SelectedItemStyle>
<AlternatingItemStyle backcolor="Cornsilk"></AlternatingItemStyle>
<ItemStyle forecolor="#000066"></ItemStyle>
<FooterStyle forecolor="#000066" backcolor="White"></FooterStyle>
<HeaderStyle font-bold="True" forecolor="White" backcolor="#FF8080"></HeaderStyle>
<PagerStyle horizontalalign="Center" forecolor="#000066" backcolor="White" mode="NumericPages"></PagerStyle>
<Fields>
<wmx:EditCommandField ButtonType="PushButton" UpdateText="Update" CancelText="Cancel" EditText="Edit"></wmx:EditCommandField>
<wmx:TemplateField HeaderText="Cover">
<ItemTemplate>
<asp:Hyperlink ImageUrl='<% #DataBinder.Eval(Container.DataItem, "CoverImageURL") %>' NavigateUrl='<% #DataBinder.Eval(Container.DataItem, "DiscID", "http://somesite.com/buy.aspx?code={0}")%>' ToolTip='<% #DataBinder.Eval(Container.DataItem, "Title", "Buy {0} Online Now!") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Text='<% #DataBinder.Eval(Container.DataItem, "CoverImageURL") %>' runat="server" />
</EditItemTemplate>
</wmx:TemplateField>
<wmx:BoundField DataField="Title" HeaderText="Title"></wmx:BoundField>
<wmx:BoundField DataField="ReleaseDate" HeaderText="Released" DataFormatString="{0:MMM yyyy}"></wmx:BoundField>
<wmx:BoundField DataField="Notes" HeaderText="Notes"></wmx:BoundField>
<wmx:BoundField DataField="Label" HeaderText="Label"></wmx:BoundField>
</Fields>
</wmx:MxDataGrid>
</form>
</body>
</html>