6 Replies - 11343 Views - Last Post: 17 June 2011 - 12:30 PM Rate Topic: -----

#1 khaos24   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-June 11

Edit, Delete function in Gridview not working!

Posted 12 June 2011 - 05:21 PM

Hello,

I have a gridview that is working the way I want it to. It is returning data from a stored procedure without a problem. I am having trouble Editing, Deleting the records from the Gridview as my application keeps erroring out at the RowEditing event. Although I am trying to use the "Edit, Delete" function from the Design view of the Gridview. Hence I am unsure what to list down as the code. I used the Select tab, Update tab & Delete tab in the sqldatasource configuration. the Select tab stored procedure works, whereas the Update & Delete tab stored procedure/sql command doesn't work. An example of the code in my Delete tab is ..
Code:
Delete from dbo.Promosteus
WHERE  ID = @ID


I don't know what else to list down as the code, as I am doing this through the Design View of the Gridview & not in actual code. But the RowEditing event handler error (Jscript) error that the application keeps throwing out, how can I overcome this? This happens everytime i try to click on Edit/Delete on the Gridview.
Can anyone point me in the right direction?

Is This A Good Question/Topic? 0
  • +

Replies To: Edit, Delete function in Gridview not working!

#2 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Edit, Delete function in Gridview not working!

Posted 12 June 2011 - 09:34 PM

Go to the code view, instead of design view, and copy and paste the code for the gridview and data source from there
Was This Post Helpful? 0
  • +
  • -

#3 khaos24   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-June 11

Re: Edit, Delete function in Gridview not working!

Posted 13 June 2011 - 06:43 AM

Here's the code, hope this helps. I tried changing the actual SQL commands into stored procedures to see if it works, & I still wasn't able to get it to work.

<asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            DataSourceID="SqlDataSource1" EnableModelValidation="True" 
                DataKeyNames="EName" CellPadding="4" ForeColor="#333333" 
                GridLines="None" HorizontalAlign="Center" AutoGenerateEditButton="True" 
                AutoGenerateDeleteButton="True">
            <AlternatingRowStyle BackColor="White" />
            <Columns>
                <asp:BoundField DataField="Name" HeaderText="Name" 
                    SortExpression="FName" ReadOnly="true"/>
                <asp:BoundField DataField="StartDate" HeaderText="Start Date" 
                    SortExpression="StartDate"  />
                <asp:BoundField DataField="EndDate" HeaderText="End Date" 
                    SortExpression="EndDate" />
                <asp:BoundField DataField="FurInfo" HeaderText="FurInfo" 
                    SortExpression="FurInfo" />
                <asp:BoundField DataField="DT" HeaderText="DT" 
                    SortExpression="DT" />
                
            </Columns>
           
        </asp:GridView>
         </ContentTemplate>
           </asp:UpdatePanel>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:Promos %>" 
            SelectCommand="DisplayD" SelectCommandType="StoredProcedure">
            DeleteCommand="exec dbo.spDisplayDelete" DeleteCommandType="StoredProcedure" 
            UpdateCommand="exec dbo.sp_DisplayUpdate" UpdateCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="DDL_List" Name="EID" 
                    PropertyName="SelectedValue" Type="Int32" />
            </SelectParameters>

Was This Post Helpful? 0
  • +
  • -

#4 khaos24   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-June 11

Re: Edit, Delete function in Gridview not working!

Posted 13 June 2011 - 08:38 AM

I'm attaching an image of the error that I get

Attached image(s)

  • Attached Image

Was This Post Helpful? 0
  • +
  • -

#5 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Edit, Delete function in Gridview not working!

Posted 14 June 2011 - 09:04 PM

you shouldn't need the "exec" on the UpdateCommand and DeleteCommand properties. It should work with just the stored procedure name same as the SelectCommand property
Was This Post Helpful? 0
  • +
  • -

#6 Nakor   User is offline

  • Professional Lurker
  • member icon

Reputation: 448
  • View blog
  • Posts: 1,504
  • Joined: 28-April 09

Re: Edit, Delete function in Gridview not working!

Posted 15 June 2011 - 08:21 PM

Can you provide the code for the entire data source. I see the SelectParameters but where are the UpdateParameters and DeleteParameters? What parameters do your SP's expect?
Was This Post Helpful? 0
  • +
  • -

#7 khaos24   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 06-June 11

Re: Edit, Delete function in Gridview not working!

Posted 17 June 2011 - 12:30 PM

I got it working, I just created events for every command such as Update, delete, RowCommand & just put code for it in the code behind. Thanks for you help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1