Frage

(asp.net dynamic data) In the db.cs file I have declared the below (relating to the 'Invoice Info' table)

[ScaffoldTable(true)]
[DisplayName("Invoice Info")]
[MetadataType(typeof(Invoice_Info_MetaData))]
[DropDownList(Role = "Role_AllPowerfulGroup")]
partial class Invoice_Info
{
}

public class Invoice_Info_MetaData
{
    [Display(Name = "id", Order = 10)]
    public object id { get; set; }

    [Display(Name = "Name", Order = 20)]
    [Required()]
    public object Name { get; set; }

    [Display(Name = "Address", Order = 30)]
    [Required()]
    public object Address { get; set; }

    [Display(Name = "County", Order = 40)]
    [Required()]
    public object County { get; set; }

On screen this displays as: enter image description here

I dont want the user to be able to delete this, so how can I remove it from the on screen options??(the icon the red arrow points to) Thanks

War es hilfreich?

Lösung

You should create custom List.aspx page for Invoice Info table (copy from List.aspx in PageTemplates folder in your project) and then you can delete code with delete button on new custom page (see ItemTemplate with LinkButton control inside of GridView). Also you can add RowDataBound event to GridView on custom page and implement hiding of delete button in Code-Behind:

protected void gvInvoiceInfo_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton delete = (LinkButton) e.Row.FindControl("DeleteLinkButton");
            delete.Visible = false;
        }
    }

where DeleteLinkButton is ID of LinkButton control inside GridView's TemplateField with actions.

More information about of page customization in ASP.NET Dynamic Data you can find at How to: Customize the Layout of an Individual Table By Using a Custom Page Template.

EDIT:

I would like to draw you attention to the fact that by default there is the possibility of deleting table item from Details.aspx page. Therefore, you should also create custom Details.aspx page in order to prevent deleting record from default Details.aspx page.

As a result you should have two custom page:

~/DynamicData/CustomPages/InvoiceInfo/List.aspx

and

~/DynamicData/CustomPages/InvoiceInfo/Details.aspx.

EDIT:

In order to implement a more integrated approach to security in Dynamic Data site see Steve's solution at Securing Dynamic Data 4 (Replay).

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top