how to hide linkbutton in edit mode of a gridview
Hi,
i want to perform several things (like checking and correcting automatically the lenght of a multiline textbox in order to avoid Truncate error, removing automatically "<" and "'" to avoid "potential danger" error etc ..) with javascript on a gridview.
If i take in the aspx file this:
<asp:CommandField ShowEditButton="True">
i have no possibility to use the OnClientClick property.
So i made some Templatefields like this:
<asp:TemplateField><ItemTemplate>
<asp:LinkButton ID="lb1" runat="server" CommandName="Edit"
></asp:LinkButton>
</ItemTemplate></asp:TemplateField>
<asp:TemplateField><EditItemTemplate>
<asp:LinkButton ID="lb2" runat="server" CommandName="Update"
OnClientClick="myfunction();"></asp:LinkButton>
</EditItemTemplate></asp:TemplateField>
<asp:TemplateField><EditItemTemplate>
<asp:LinkButton ID="lb3" runat="server" CommandName="Cancel"
></asp:LinkButton>
</EditItemTemplate></asp:TemplateField>
My problem is now that the linkbutton "Edit" not only appears in normal
mode, but also in Edit mode, together with "Update" and "Cancel". I don't understand why, but now i want to get rid of it.
I did this in code-behind:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If (e.Row.RowState And DataControlRowState.Edit) = DataControlRowState.Edit Then
Dim lb As LinkButton
lb = e.Row.FindControl("lb1")
lb.Visible = False
End If
End Sub
Now the linkbutton is invisible but only for the selected row and there is still an empty
space in the gridview.
Any way to solve this?
Thanks
|