Hi,
I have a Listview, where some users (depending on their role) are allowed to edit, delete and insert columns and others are only allowed to read the data.
Hence I have set the Insert, Delete and Edit buttons as invisible by default. In the code behind I tried to make the buttons visible for the user with the right role. This works fine for the Edit button and the Delete button, where I use the GridView_RowDataBound code from Chapter 14 page 495, with some adaptation because my ListView shows the columns in a single line.
For the Insert button however I can't find an Event that targets the Insert button. I tried ItemCommand, ItemCreated, ItemDataBound, DataBinding, Load for the ListView and pageLoad as well. Is there a way to target the Insert button?
Even more attractive would be to make the whole Insert template visible/invisible by a single command, but I guess that's impossible.
My code is
Code:
<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" ValidationGroup="Insert" Visible="False" />
//Code behind
protected void ListViewSchalen_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (Roles.IsUserInRole("Neurologie"))
{
switch (e.Item.ItemType)
{
case ListViewItemType.DataItem:
LinkButton myDeletebtn = (LinkButton)e.Item.FindControl("DeleteButton");
if (myDeletebtn != null)
{
myDeletebtn.Visible = true;
}
LinkButton myEditbtn = (LinkButton)e.Item.FindControl("EditButton");
if (myEditbtn != null)
{
myEditbtn.Visible = true;
}
LinkButton myInsertbtn = (LinkButton)e.Item.FindControl("InsertButton");
if (myInsertbtn != null)
{
myInsertbtn.Visible = true;
}
LinkButton myCancelbtn = (LinkButton)e.Item.FindControl("CancelButton");
if (myCancelbtn != null)
{
myCancelbtn.Visible = true;
}
break;
}
}
}
thanks
Hans