Cragly
asked on
Hide/Show HyperLink in DataGrid
Hi All,
I want to be able to hide or show a hyperlinks in a template column within a DataGrid. I select users from a database and bind them to the grid. If a user can not be edited or deleted I want to be able to hide the edit/delete hyperlinks for that particular record in the data grid. I have included my template column code below. If there is a better way of achieving the same result then I am happy to change my code.
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center">< /ItemStyle >
<ItemTemplate>
<asp:HyperLink id="hlkUpdate" runat="server" NavigateUrl='<%# "usersUpdate.aspx?uid=" + DataBinder.Eval(Container. DataItem, "UserID") %>'>edit</asp:HyperLink> |
<asp:HyperLink id="hlkDelete" runat="server" NavigateUrl='<%# "usersDelete.aspx?uid=" + DataBinder.Eval(Container. DataItem, "UserID") %>'>delete</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
Many thanks in advance
Cragly
I want to be able to hide or show a hyperlinks in a template column within a DataGrid. I select users from a database and bind them to the grid. If a user can not be edited or deleted I want to be able to hide the edit/delete hyperlinks for that particular record in the data grid. I have included my template column code below. If there is a better way of achieving the same result then I am happy to change my code.
<asp:TemplateColumn>
<ItemStyle HorizontalAlign="Center"><
<ItemTemplate>
<asp:HyperLink id="hlkUpdate" runat="server" NavigateUrl='<%# "usersUpdate.aspx?uid=" + DataBinder.Eval(Container.
<asp:HyperLink id="hlkDelete" runat="server" NavigateUrl='<%# "usersDelete.aspx?uid=" + DataBinder.Eval(Container.
</ItemTemplate>
</asp:TemplateColumn>
Many thanks in advance
Cragly
how do you determine if to show/hide link? Is there a value in datatable? If so, what's the field name and type?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much guys for your help it worked a treat. Here is the final code used for anybody with the same problem.
private void dgCategories_ItemDataBound (object sender, System.Web.UI.WebControls. DataGridIt emEventArg s e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingIt em)
{
DataRowView row = (DataRowView)e.Item.DataIt em;;
if (row["CanEdit"].ToString() != "1")
{
((HyperLink)e.Item.Cells[0 ].FindCont rol("hlkUp date")).En abled = false;
((HyperLink)e.Item.Cells[0 ].FindCont rol("hlkDe lete")).En abled = false;
}
}
}
You could not help me on another issue that I have posted could you??
https://www.experts-exchange.com/questions/21787495/C-ASP-NET-Checkbox-List-Problem.html
Many thanks
Cragly
private void dgCategories_ItemDataBound
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingIt
{
DataRowView row = (DataRowView)e.Item.DataIt
if (row["CanEdit"].ToString()
{
((HyperLink)e.Item.Cells[0
((HyperLink)e.Item.Cells[0
}
}
}
You could not help me on another issue that I have posted could you??
https://www.experts-exchange.com/questions/21787495/C-ASP-NET-Checkbox-List-Problem.html
Many thanks
Cragly
Why even go to dgCategories_ItemDataBound when you can hide them in html view?!
That's why I asked you to provide me details in my first posr but you never answered.
That's why I asked you to provide me details in my first posr but you never answered.