i have a grid as below:
with the following code behind to save the data to the dabase:
I keep getting the error on line 53
I would really appreciate a solution. I am sure I am almost there but not quite working.
Simon
| <telerik:RadGrid ID="RadGrid1" runat="server" GridLines="None" AllowPaging="True" |
| AllowSorting="True" AutoGenerateColumns="False" Width="828px" OnNeedDataSource="RadGrid1_NeedDataSource" |
| OnUpdateCommand="RadGrid1_UpdateCommand" EnableAjaxSkinRendering="true" Skin="Default" |
| OnInsertCommand="RadGrid1_InsertCommand"> |
| <MasterTableView DataKeyNames="ProductID" GridLines="None" Width="100%" CommandItemDisplay="Top"> |
| <Columns> |
| <telerik:GridTemplateColumn HeaderText="Prod.Image" UniqueName="ProductImage"> |
| <ItemTemplate> |
| <asp:Image ID="Image1" ImageUrl='<%# Link.ToProductThumbNail(Eval("Thumbnail").ToString()) %>' |
| runat="server" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn HeaderText="Prod. Number" UniqueName="ProductNoImage"> |
| <ItemTemplate> |
| <asp:Image ID="Image2" ImageUrl='<%# Link.ToProductNo(Eval("ProductNo").ToString()) %>' |
| runat="server" /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="Name" HeaderText="Prod.Name" UniqueName="ProdName"> |
| </telerik:GridBoundColumn> |
| <telerik:GridHTMLEditorColumn DataField="Description" HeaderText="Prod.Desc" UniqueName="ProdDescription"> |
| </telerik:GridHTMLEditorColumn> |
| <%-- <telerik:GridBoundColumn DataField="Description" HeaderText="Prod.Desc" UniqueName="ProdDescription"> |
| </telerik:GridBoundColumn>--%> |
| <telerik:GridBoundColumn DataField="Price" HeaderText="Price" DataFormatString="{0:£0.00}" |
| UniqueName="ProdPrice"> |
| </telerik:GridBoundColumn> |
| <telerik:GridTemplateColumn UniqueName="SelectProd"> |
| <ItemTemplate> |
| <asp:HyperLink ID="HyperLink1" runat="server" Text="Select" NavigateUrl='<%# "ProductDetail.aspx?CategoryID=" + |
| Request.QueryString["CategoryID"] + |
| "&ProductIDProductID=" + Eval("ProductID") %>'> |
| </asp:HyperLink> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridCheckBoxColumn Visible="false" DataField="PromoFront" HeaderText="Cat.Promo" |
| UniqueName="PromoFront"> |
| </telerik:GridCheckBoxColumn> |
| <telerik:GridCheckBoxColumn Visible="false" DataField="PromoDept" HeaderText="Dept.Promo" |
| UniqueName="PromoDept"> |
| </telerik:GridCheckBoxColumn> |
| <telerik:GridEditCommandColumn> |
| </telerik:GridEditCommandColumn> |
| </Columns> |
| <EditFormSettings ColumnNumber="2" CaptionFormatString="Edit details for:{0}" CaptionDataField="Name"> |
| <FormTableItemStyle Wrap="False"></FormTableItemStyle> |
| <FormCaptionStyle></FormCaptionStyle> |
| <FormMainTableStyle CellSpacing="0" CellPadding="3" Width="100%" /> |
| <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" Height="110px" |
| Width="100%" /> |
| <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> |
| <FormStyle Width="100%" BackColor="#EEF2EA"></FormStyle> |
| <EditColumn UpdateText="Update" UniqueName="EditCommandColumn1" CancelText="Cancel"> |
| </EditColumn> |
| <FormTableButtonRowStyle HorizontalAlign="Right"></FormTableButtonRowStyle> |
| </EditFormSettings> |
| <ExpandCollapseColumn Visible="False"> |
| <HeaderStyle Width="19px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <RowIndicatorColumn Visible="False"> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| </MasterTableView> |
| </telerik:RadGrid> |
| protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) |
| { |
| //Get the GridEditableItem of the RadGrid |
| GridEditableItem editedItem = e.Item as GridEditableItem; |
| //Get the primary key value using the DataKeyValue. |
| string id = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ProductID"].ToString(); |
| //Access the textbox from the edit form template and store the values in string variables. |
| //string productno = (editedItem["ProductNo"].Controls[0] as TextBox).Text; |
| string name = (editedItem["ProdName"].Controls[0] as TextBox).Text; |
| string description = (editedItem["ProdDescription"].Controls[0] as GridHTMLEditorColumnEditor).Text; |
| string price = (editedItem["ProdPrice"].Controls[0] as TextBox).Text; |
| //string thumbnail = (editedItem["ProdThumbnail"].Controls[0] as TextBox).Text; |
| //string image = (editedItem["ProdImage"].Controls[0] as TextBox).Text; |
| string promoDept = (editedItem["PromoDept"].Controls[0] as CheckBox).Checked.ToString(); |
| string promoFront = (editedItem["PromoFront"].Controls[0] as CheckBox).Checked.ToString(); |
| try |
| { |
| CatalogAccess.UpdateProduct(id,name,description.ToString(),price,promoDept, promoFront); |
| } |
| catch (Exception ex) |
| { |
| RadGrid1.Controls.Add(new LiteralControl("Unable to update Category. Reason: " + ex.Message)); |
| e.Canceled = true; |
| } |
| } |
| Object reference not set to an instance of an object. |
| 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.NullReferenceException: Object reference not set to an instance of an object. |
| Source Error: |
| Line 51: //string productno = (editedItem["ProductNo"].Controls[0] as TextBox).Text; |
| Line 52: string name = (editedItem["ProdName"].Controls[0] as TextBox).Text; |
| Line 53: string description = (editedItem["ProdDescription"].Controls[0] as GridHTMLEditorColumnEditor).Text; |
| Line 54: string price = (editedItem["ProdPrice"].Controls[0] as TextBox).Text; |
| Line 55: //string thumbnail = (editedItem["ProdThumbnail"].Controls[0] as TextBox).Text; |
Simon