The standard GridView pattern is link buttons are associated with a Gridview template; Item template, Edit template, etc. Toggling the GridView templates shows the associated link button(s) for that template. I recommend going through the following tutorial.
How can I make linkbutton visible in Gridview?
HB
1
Reputation point
The OnClick="lnkRelease_Click" does not change the boolean values for my linkbutton controls in the itemtemplate.
Any help on pointing me to the right direction, would be appreciated.
My ASP page:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id,InsertDate" DataSourceID="HRD" ShowFooter="True" HorizontalAlign="Center">
<Columns>
<asp:TemplateField ShowHeader="False">
<FooterTemplate>
<asp:LinkButton ID="lnkInsert" runat="server" CssClass="button" OnClick="lnkInsert_Click" ValidationGroup="Insert">Add</asp:LinkButton>
<asp:LinkButton ID="LnkDeduct" runat="server" OnClick="LnkDeduct_Click" ValidationGroup="Insert">Deduct</asp:LinkButton>
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton ID="lnkRelease" runat="server" Visible="true" Text="Release" OnClick="lnkRelease_Click"></asp:LinkButton>
<asp:LinkButton ID="lnkLock" runat="server" Visible="false" Text="Lock"></asp:LinkButton>
<asp:LinkButton ID="lnkDel" runat="server" Visible="false"
CommandName="Delete" OnClientClick="return confirm('Are you sure you want to Delete?');" Text="Delete" OnClick="lnkDel_Click"></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="100px" Wrap="False" />
</asp:TemplateField>
And my code page for the OnClick event:
protected void lnkRelease_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView1.Rows)
{
((LinkButton)row.FindControl("lnkLock")).Visible = true;
((LinkButton)row.FindControl("lnkDel")).Visible = true;
((LinkButton)row.FindControl("lnkRelease")).Visible = false;
}
}
2 answers
Sort by: Most helpful
-
-
HB 1 Reputation point
2022-07-25T17:01:05.683+00:00 Thanks,
I had figured it out to use the RowCommand instead:
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer); if (e.CommandName == "Release") { ((LinkButton)row.FindControl("lnkLock")).Visible = true; ((LinkButton)row.FindControl("lnkDel")).Visible = true; ((LinkButton)row.FindControl("lnkRelease")).Visible = false; } else { ((LinkButton)row.FindControl("lnkLock")).Visible = false; ((LinkButton)row.FindControl("lnkDel")).Visible = false; ((LinkButton)row.FindControl("lnkRelease")).Visible = true; } }