Databases Reference
In-Depth Information
<asp:GridView ID=”gridView” runat=”server”>
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:DynamicHyperLink runat=”server” Action=”Edit” Text=”Edit”/>
<asp:DynamicHyperLink runat=”server” Action=”Delete”
Text= ”Delete”/>
<asp:DynamicHyperLink runat=”server” Text=”Details” />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:DynamicHyperLink ID=”insertLink” runat=”server”>
Insert new item
</asp:DynamicHyperLink>
The Edit and Delete hyperlink controls are generated dynamically, a separate instance for
each row displayed in the GridView control. The best way to manipulate them in this
scenario is by specifying an OnInit event handler. Here is how you need to modify
markup of the Edit hyperlink:
<asp:DynamicHyperLink runat=”server” Action=”Edit” Text=”Edit”
OnInit=”EditLink_Init” />
In the code-behind, you access the dynamically generated control through the sender argu-
ment the event handler receives. To determine if the user should see the Edit link, call the
CanUpdate of the MetaTable object associated with the current page. Based on the boolean
value it returns, you simply set link's Visible property to show or hide it:
protected void EditLink_Init(object sender, EventArgs e)
{
((DynamicHyperLink)sender).Visible = this.table.CanUpdate(this.User);
}
Similar changes are needed for the Delete and Insert hyperlinks in the List page template
as well. In other words, in page markup, you need to specify the OnInit event handlers for
both of these controls. In the code-behind, create the event handlers and implement them
by calling CanDelete and CanInsert methods of the MetaTable class, respectively. Because
the code is so similar to what was done for the Edit link, it is not shown here; you can
find it in the sample project accompanying the topic.
Search WWH ::




Custom Search