When you create an edit button in each row of the Gridview using CommandField , after clicking the button, the update / cancel buttons are displayed, so you can accept / cancel the changes. However, I want an edit button that has a tooltip text, and since the CommandField does not have a tooltip property, I used a TemplateField . It worked with the delete button, but I have problems with the edit button:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" DataMember="DefaultView" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames=FIELD,FIELD,FIELD" CellPadding="4" ForeColor="#333333" Width="90%" Height="90%" Font-Size="Small"> <RowStyle BackColor="#EFF3FB" /> <Columns> <asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True" SortExpression="FIELD" /> <asp:BoundField DataField="FIELD" HeaderText="FIELD" SortExpression="FIELD" /> <asp:BoundField DataField="FIELD" HeaderText="FIELD" SortExpression="FIELD" /> <asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True" SortExpression="FIELD" /> <asp:BoundField DataField="FIELD" HeaderText="FIELD" ReadOnly="True" SortExpression="FIELD" /> <asp:BoundField DataField="FIELD" HeaderText="FIELD" SortExpression="FIELD" /> <asp:CommandField ButtonType="Image" Visible="true" EditText="Edit" ShowEditButton="True" EditImageUrl="images/pencil1.png"></asp:CommandField> <asp:TemplateField > <ItemTemplate> <asp:ImageButton ID="deleteButton" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('ΒΏAre you sure?');" ToolTip="delete" ImageUrl="images/DeleteRed1.png" /> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#2461BF" /> <AlternatingRowStyle BackColor="White" /> </asp:GridView> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DBUserInterfaceConnectionString %>" SelectCommand="SELECT ... FROM ... INNER JOIN ... ON ..." DeleteCommand="DELETE FROM ... WHERE ...=@param ;" UpdateCommand="UPDATE ... SET ... = @param, ... = @param2 WHERE ... = @param3 and ... = @param4 and ... = @param5;" > </asp:SqlDataSource>
As I said, I replaced CommandField with:
<asp:TemplateField > <ItemTemplate> <asp:ImageButton ID="editButton" runat="server" CommandName="Edit" Text="Edit" ToolTip="Edit" ImageUrl="images/pincel1.png" /> </ItemTemplate> </asp:TemplateField >
but the Update / Cancel buttons are not displayed, so I canβt update / edit anything. Why is this happening?
Any ideas for implementing a successful edit button?
NOTES:
Both buttons do not have vb code behind, for some reason the delete button only works with DeleteCommand in SqlDataSource , and if I try to delete this command, it gives an error message because DeleteCommand is not specified.
UpdateCommand has no purpose, it can be deleted. I could use it for the refresh button instead of the edit button, but when I tried, it says @params unknown, so I decided to use the edit button instead.
source share