This is a migrated thread and some comments may be shown as answers.

issues with my insert/update/delete

3 Answers 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Gina
Top achievements
Rank 1
Gina asked on 31 Aug 2009, 08:07 PM
I have created a grid that i need to insert a new record, delete an record or update... When I run update it gives me the error - Object reference not set to an instance of an object... Can someone help me out... I just do not see what i am misssing... 

 

  <telerik:RadGrid ID="rgEditPhoneList" runat="server"
            AllowPaging="True"
            AllowSorting="True"
            GridLines="None"
            DataSourceID="SqlDataSource1"
            Visible="False"
            OnItemUpdate="rgEditPhoneList_ItemUpdated"
            OnDataBound="rgEditPhoneList_DataBound"
            OnItemInserted="rgEditPhoneList_ItemInserted"
            OnItemDeleted="rgEditPhoneList_ItemDeleted"
            AllowAutomaticUpdates ="True"
            AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True"
            AutoGenerateColumns="False"
            PageSize="50">
        <ExportSettings>
            <Pdf PaperSize="Letter" FontType="Subset"></Pdf>
            <Excel Format="Html"></Excel>
            <Csv RowDelimiter="NewLine" ColumnDelimiter="Comma"></Csv>
        </ExportSettings>
        <MasterTableView CurrentResetPageIndexAction="SetPageIndexToFirst"
                        Dir="LTR"
                        Frame="Border"
                        TableLayout="Auto"
                        CommandItemDisplay="Top"
                        AutoGenerateColumns="False"
                        DataKeyNames="ID"
                        DataSourceID="SqlDataSource1">
            <RowIndicatorColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"
                Visible="False">
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn CurrentFilterFunction="NoFilter" FilterListOptions="VaryByDataType"
                Visible="False" Resizable="False">
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
            <ItemStyle CssClass="MyImageButton" />
        </telerik:GridEditCommandColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="ID" DataType="System.Int32"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None"
                    HeaderText="ID" SortExpression="ID"
                    UniqueName="ID" ReadOnly="True">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="SortOrder" DataType="System.Int32"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="SortOrder"
                    SortExpression="SortOrder" UniqueName="SortOrder">
                </telerik:GridBoundColumn>
               
                <telerik:GridDropDownColumn DataSourceID="sqlKMAgrid" ListTextField="KMA_LongDesc" ListValueField="ID"
                SortExpression="KMA_LongDesc" HeaderText="KMA" DropDownControlType="DropDownList"
                DataField="KMA_LongDesc" ColumnEditorID="GridDropDownColumnEditor1" >
                 </telerik:GridDropDownColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="KMA_LongDesc"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="KMA_LongDesc"
                    SortExpression="KMA_LongDesc" UniqueName="KMA_LongDesc">
                </telerik:GridBoundColumn>
             <%--   <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="KMA_ID" DataType="System.Int32"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="KMA_ID"
                    SortExpression="KMA_ID" UniqueName="KMA_ID">
                </telerik:GridBoundColumn>--%>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="DispatchLocation"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="DispatchLocation"
                    SortExpression="DispatchLocation" UniqueName="DispatchLocation">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Sys" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Sys" SortExpression="Sys" UniqueName="Sys">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Prin" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Prin" SortExpression="Prin" UniqueName="Prin">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Site" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Site" SortExpression="Site" UniqueName="Site">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Co_Div" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Co_Div" SortExpression="Co_Div" UniqueName="Co_Div">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Name" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Name" SortExpression="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Title" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Title" SortExpression="Title" UniqueName="Title">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="OfficeNumber"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="OfficeNumber"
                    SortExpression="OfficeNumber" UniqueName="OfficeNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Extention" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Extention" SortExpression="Extention" UniqueName="Extention">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="CellNumber"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="CellNumber"
                    SortExpression="CellNumber" UniqueName="CellNumber">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Monday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Monday" SortExpression="Monday" UniqueName="Monday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Tuesday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Tuesday" SortExpression="Tuesday" UniqueName="Tuesday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Wednesday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Wednesday" SortExpression="Wednesday" UniqueName="Wednesday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Thursday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Thursday" SortExpression="Thursday" UniqueName="Thursday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Friday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Friday" SortExpression="Friday" UniqueName="Friday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Saturday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Saturday" SortExpression="Saturday" UniqueName="Saturday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Sunday" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Sunday" SortExpression="Sunday" UniqueName="Sunday">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="StartHour" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="StartHour" SortExpression="StartHour" UniqueName="StartHour">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="EndHour" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="EndHour" SortExpression="EndHour" UniqueName="EndHour">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Notes" FilterListOptions="VaryByDataType"
                    ForceExtractValue="None" HeaderText="Notes" SortExpression="Notes" UniqueName="Notes">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="StartDate" DataType="System.DateTime"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="StartDate"
                    SortExpression="StartDate" UniqueName="StartDate">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="StopDate" DataType="System.DateTime"
                    FilterListOptions="VaryByDataType" ForceExtractValue="None" HeaderText="StopDate"
                    SortExpression="StopDate" UniqueName="StopDate">
                </telerik:GridBoundColumn>
                 <telerik:GridButtonColumn ConfirmText="Delete this product?" ButtonType="ImageButton"
                 CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                        <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
                    </telerik:GridButtonColumn>

            </Columns>
              <EditFormSettings ColumnNumber="2" CaptionDataField="ID" CaptionFormatString="Edit properties of Product {0}">
                   <FormTableItemStyle Wrap="False"></FormTableItemStyle>
                    <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                    <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                        Width="100%" />
                    <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
                    <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                    <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                        UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                    </EditColumn>
                    <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
                </EditFormSettings>
           
        </MasterTableView>
     
    </telerik:RadGrid>
     </ContentTemplate>
    </asp:UpdatePanel>
   
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:EDCCConnectString %>"
       SelectCommand="DSRV_SelectKMA_PhoneList" UpdateCommandType="StoredProcedure"
        SelectCommandType="StoredProcedure"
        UpdateCommand="update TL_DSRV_KMA_PhoneList
        set SortOrder = @SortOrder, 
  KMA_LongDesc   = @KMA_ID,
  DispatchLocation = @DispatchLocation,
  [Sys]   = @sys,
  Prin   = @Prin,
  [Site]   = @Site,
  Co_Div   = @Co_Div,
  Name   = @Name,
  Title   = @Title,
  OfficeNumber = @OfficeNumber,
  Extention  = @Extention,
  CellNumber  = @CellNumber,
  Monday   = @Monday,
  Tuesday   = @Tuesday,
  Wednesday  = @Wednesday,
  Thursday  = @Thursday,
  Friday   = @Friday,
  Saturday  = @Saturday,
  Sunday   = @Sunday,
  StartHour  = @StartHour,
  EndHour   = @EndHour,
  Notes   = @Notes,
  StartDate  = @StartDate,
  StopDate  = @StopDate
  where ID = @ID"
  
        InsertCommand="INSERT INTO TL_DSRV_KMA_PhoneList (SortOrder, 
  KMA_ID,
  DispatchLocation,
  [Sys],
  Prin,
  [Site],
  Co_Div,
  Name,
  Title,
  OfficeNumber,
  Extention,
  CellNumber,
  Monday,
  Tuesday,
  Wednesday,
  Thursday,
  Friday,
  Saturday,
  Sunday,
  StartHour,
  EndHour,
  Notes,
  StartDate,
  StopDate) values(@SortOrder, 
  @KMA_ID,
  @DispatchLocation,
  @Sys,
  @Prin,
  @Site,
  @Co_Div,
  @Name,
  @Title,
  @OfficeNumber,
  @Extention,
  @CellNumber,
  @Monday,
  @Tuesday,
  @Wednesday,
  @Thursday,
  @Friday,
  @Saturday,
  @Sunday,
  @StartHour,
  @EndHour,
  @Notes,
  @StartDate,
  @StopDate)"
        DeleteCommand="DELETE FROM [TL_DSRV_KMA_PhoneList] WHERE [ID] = @ID" >
        <SelectParameters>
            <asp:ControlParameter ControlID="ddlKMA" Name="KMA_ID"
                PropertyName="SelectedValue" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="ID" Type="Int32" />
            <asp:Parameter Name="SortOrder" Type="Int32" />
            <asp:Parameter Name="KMA_LongDesc" Type="Int32" />
            <asp:Parameter Name="DispatchLocation" Type="String" />
            <asp:Parameter Name="Sys" Type="String" />
            <asp:Parameter Name="Prin" Type="String" />
            <asp:Parameter Name="Site" Type="String" />
            <asp:Parameter Name="Co_Div" Type="String" />
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="OfficeNumber" Type="String" />
            <asp:Parameter Name="Extention" Type="String" />
            <asp:Parameter Name="CellNumber" Type="String" />
            <asp:Parameter Name="Monday" Type="String" />
            <asp:Parameter Name="Tuesday" Type="String" />
            <asp:Parameter Name="Wednesday" Type="String" />
            <asp:Parameter Name="Thursday" Type="String" />
            <asp:Parameter Name="Friday" Type="String" />
            <asp:Parameter Name="Saturday" Type="String" />
            <asp:Parameter Name="Sunday" Type="String" />
            <asp:Parameter Name="StartHour" Type="String" />
            <asp:Parameter Name="EndHour" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="StateDate" Type="DateTime" />
            <asp:Parameter Name="StopDate" Type="DateTime" />           
        </UpdateParameters>
        <InsertParameters>
            <asp:Parameter Name="SortOrder" Type="Int32" />
            <asp:Parameter Name="KMA_LongDesc" Type="Int32" />
            <asp:Parameter Name="DispatchLocation" Type="String" />
            <asp:Parameter Name="Sys" Type="String" />
            <asp:Parameter Name="Prin" Type="String" />
            <asp:Parameter Name="Site" Type="String" />
            <asp:Parameter Name="Co_Div" Type="String" />
            <asp:Parameter Name="Name" Type="String" />
            <asp:Parameter Name="Title" Type="String" />
            <asp:Parameter Name="OfficeNumber" Type="String" />
            <asp:Parameter Name="Extention" Type="String" />
            <asp:Parameter Name="CellNumber" Type="String" />
            <asp:Parameter Name="Monday" Type="String" />
            <asp:Parameter Name="Tuesday" Type="String" />
            <asp:Parameter Name="Wednesday" Type="String" />
            <asp:Parameter Name="Thursday" Type="String" />
            <asp:Parameter Name="Friday" Type="String" />
            <asp:Parameter Name="Saturday" Type="String" />
            <asp:Parameter Name="Sunday" Type="String" />
            <asp:Parameter Name="StartHour" Type="String" />
            <asp:Parameter Name="EndHour" Type="String" />
            <asp:Parameter Name="Notes" Type="String" />
            <asp:Parameter Name="StateDate" Type="DateTime" />
            <asp:Parameter Name="StopDate" Type="DateTime" /> 
        </InsertParameters>
        <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>

    </asp:SqlDataSource>
   
    <asp:SqlDataSource ID="sqlKMAgrid" runat="server"
        ConnectionString="<%$ ConnectionStrings:EDCCConnectString %>"
        SelectCommand="SELECT [ID], [KMA_LongDesc] FROM [TL_KMA_Reference]"></asp:SqlDataSource>
       
     

 

 

 protected void rgEditPhoneList_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
    {

        GridEditableItem item = (GridEditableItem)e.Item;
        String Name = item.GetDataKeyValue("ID").ToString();

        if (e.Exception != null)
        {
            e.KeepInEditMode = true;
            e.ExceptionHandled = true;

            SetMessage("ID " + Name + " cannot be updated. Reason: " + e.Exception.Message);
        }
        else
        {
            SetMessage("ID " + Name + " is updated!");
        }
    }

    private void SetMessage(string message)
    {
        gridMessage = message;
    }

    private void DisplayMessage(string text)
    {
        rgEditPhoneList.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
    }

    private string gridMessage = null;

    protected void rgEditPhoneList_DataBound(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(gridMessage))
        {
            DisplayMessage(gridMessage);
        }
    }
   
   

 

 

 

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 01 Sep 2009, 01:55 PM
Hi Gina,

Please post the exception stack trace.

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Gina
Top achievements
Rank 1
answered on 01 Sep 2009, 02:34 PM
the exception that i am getting is -- NullReferenceException...  Is this what you needed to know ?
0
Gina
Top achievements
Rank 1
answered on 01 Sep 2009, 04:10 PM
I believe this was my issue UpdateCommandType="StoredProcedure".. thank you for trying to help...
Tags
Grid
Asked by
Gina
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Gina
Top achievements
Rank 1
Share this question
or