We help IT Professionals succeed at work.

Cannot get my gridview to delete a row.

Medium Priority
212 Views
Last Modified: 2013-11-19
The problem is, it only works when i click on the edit button & it turns my bound fields into to editable textboxes.

The problem is I am already using the update button when I click on the edit button.
So currently my gridview displays EDIT button  when I press this button my template field displays  update - & Cancel. Is there anyway add the delete button to this as well.

<Columns>
                        <asp:CommandField showeditbutton="True" showdeletebutton="true" HeaderText="Add Remove Collegaue" ButtonType="Button" />
 
                        <asp:TemplateField HeaderText="ColleagueID" SortExpression="ColleagueID">
                            <EditItemTemplate>
                                <asp:TextBox ID="ColleagueID" runat="server" Text='<%# Bind("ColleagueID") %>'></asp:TextBox>
 
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="lblColleagueID" runat="server" Text='<%# Bind("ColleagueID") %>'></asp:Label>
 
                            </ItemTemplate>
                        </asp:TemplateField>
                            <asp:TemplateField HeaderText="Colleague Name" SortExpression="ColleagueName">
                                <EditItemTemplate>
                                    <asp:TextBox ID="ColleagueName" runat="server" Text='<%# Bind("ColleagueName") %>'></asp:TextBox>
 
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblColleagueName" runat="server" Text='<%# Bind("ColleagueName") %>'></asp:Label>
 
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Mobile" SortExpression="Mobile">
                                <EditItemTemplate>
                                    <asp:TextBox ID="Mobile" runat="server" Text='<%# Bind("Mobile") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblMobile" runat="server" Text='<%# Bind("Mobile") %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="Extension" SortExpression="Extension">
                                <EditItemTemplate>
                                    <asp:TextBox ID="Extension" runat="server" Text='<%# Bind("Extension") %>'></asp:TextBox>
 
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblExtension" runat="server" Text='<%# Bind("Extension") %>'></asp:Label>
 
                                </ItemTemplate>
                            </asp:TemplateField>
                    </Columns>
                </asp:GridView>
                           
                <asp:objectdatasource id="objdsColleagueDetails" runat="server" Typename="WAB_DataAccessWS.WAB_DataAccessWS" SelectMethod="selColleagueDetails"
 
                                            UpdateMethod="updColleagueDetails" DeleteMethod="delColleagueDetails" InsertMethod="insColleaguedetails">
 
                    <selectparameters>
                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn"  Propertyname="Value" Type="String" />
 
                        <asp:ControlParameter ControlID="ddlDepartment" Name="intDepartmentID" PropertyName="SelectedValue" Type="Int32" />
 
                    </selectparameters>
                    <UpdateParameters>
                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn" Propertyname="Value" Type="String" />
 
                        <asp:Parameter Name="ColleagueID" Type="Int32" />
                        <asp:Parameter Name="ColleagueName" Type="String" />
                        <asp:Parameter Name="Mobile" Type="String" />
                        <asp:Parameter Name="Extension" Type="String" />
                    </UpdateParameters>
                    <DeleteParameters>
                        <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn" Propertyname="Value" Type="String" />
 
                        <asp:Parameter Name="ColleagueID" Type="Int32" />
                        <asp:Parameter Name="ColleagueName" Type="String" />
                        <asp:Parameter Name="Mobile" Type="String" />
                        <asp:Parameter Name="Extension" Type="String" />
                    </DeleteParameters>
                    <InsertParameters>
                         <asp:controlparameter ControlID="hdnMainConnStr" Name="strConn" Propertyname="Value" Type="String" />
 
                        <asp:Parameter Name="ColleagueID" Type="Int32" />
                        <asp:Parameter Name="ColleagueName" Type="String" />
                        <asp:Parameter Name="Mobile" Type="String" />
                        <asp:Parameter Name="Extension" Type="String" />
                    </InsertParameters>
                </asp:objectdatasource>

Open in new window

Comment
Watch Question

David RobitailleAnalyst Programmer

Commented:
you could amnualy add a button to the GridView. the important part is only to set the CommandName="Delete"
Here a link that explait how to do it and a little more...
http://www.codeproject.com/KB/webforms/GridViewConfirmDelete.aspx
David RobitailleAnalyst Programmer

Commented:
oops, amnualy = manually

Author

Commented:
Thanks for that but i am using a webservice to call a sp that deletes the row.

the only problem i am having is it will not work unless my rows have been changed to textboxes as per my edit template fields.
Analyst Programmer
Commented:
Whyit will not work bacause of that?
the "Delete" function is called by the datasource, no matter wath is behind. the only thing you have to do is to add a botton in whatever template you want to use and set it<s CommandName="Delete". the link i provided is just an exemple of that. it do a little more (confirmation, etc) but the question was about adding a delete button, no?
Why the fact that your row have been changed to textboxes change anything in that? do you acces it in some code behind code you dident posted?
 

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
thanks for that.
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.