visual studio 2010 - How to create DropDownList in VS2010 .NET 4.0 Dynamic Data Website -


i'm newbie visual studio 2010 .net 4.0 dynamic data. i'm trying simple dropdown list web site (written in c#).

i've got field called protocol (as in tcp-protocol). want user able choose 1 of static values. in olden days classic asp , html have used this:

<form name=form1 method="post" action="./insert.asp"> ... <select name="protocol" size="1"> <option value="https" selected>https <option value="sftp">sftp <option value="ftps">ftps </select> ... </form> 

... , handled database in ./insert.asp.

so far i've found instruction on how in visual studio 2008 (.net 3.5), doesn't work in ws2010 , .net 4.0: http://csharpbits.notaclue.net/2008/07/dynamic-data-and-field-templates-your.html

following instructions in http://www.asp.net/web-forms/videos/aspnet-dynamic-data i've figured in order customize fields need

  • create file custom code in app_code folder (myservice.cs).
  • create 'public partial class' ms-sql -table (service).

here's (¿pathetic?) effort (app_code/myservice.cs):

// myservice.cs using system; using system.componentmodel.dataannotations; using system.web; using system.componentmodel; [metadatatype(typeof(servicemetadata))] public partial class service { } public class servicemetadata { [enumdatatype(typeof(protocoltype))] public object protocol { get; set; } } public enum protocoltype { https, sftp, ftps } 

this builds ok, running ends "argumentexception unhandled user code / value passed in must enum base or underlying type enum, such int32." message in \dynamicdata\fieldtemplates\enumeration.ascx.cs -file.

help appreciated.

ok, since nobody has tried answer this, i'll try answer own question.

seems me there not out-of-the-box method problem. however, in mind (please correct me if i'm wrong) there 3 possible solutions problem:

  1. change database structure
    • add new table, contains protocols , link service table:
      • add protocols -table containing these fields.
        • protocols.id (int, primary key)
        • protocols.protocol (char(10))
    • delete (drop) service.protocol -field
    • add service.protocols_id -field.
    • make relation: fk:service.protocols_id --references-->> pk:protocols.id
  2. change service.protocol -field numeric (int)

  3. create own fieldtemplate

    • requires in-depth knowledge on .net 4.0, dynamicdata, c# (or whatever programming language is), data context (=classes represent database entities)
    • you can started right-clicking ...\dynamicdata\fieldtemplates\ -folder, choose dynamicdatafield, rename mydropdownlist, click add.
    • more on subject: http://msdn.microsoft.com/en-us/library/cc488522.aspx

comments welcome.


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -