[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Cannot get my gridview to delete a row.

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

0
aneilg
Asked:
aneilg
  • 3
  • 2
1 Solution
 
David RobitailleAnalyst ProgrammerCommented:
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
0
 
David RobitailleAnalyst ProgrammerCommented:
oops, amnualy = manually
0
 
aneilgAuthor 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.
0
 
David RobitailleAnalyst ProgrammerCommented:
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?
 
0
 
aneilgAuthor Commented:
thanks for that.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now