c# - How to bind complex objects to Telerik's RadGrid -


i have create table monitor list of streams. table, can see attached, must have following features:

  • the stream description (or name) monitored
  • the type (input, output or both)
  • the results of particular day (and here problem)

this desidered result: enter image description here

the data streams provided web service, via json.

i planned on doing radgrid, have difficulties in implementation.

this model pass:

[datacontractformat] public class streamoutputdto : basedto {     public string name { get; set; }     public string type { get; set; }     public list<detailstream> details { get; set; } } 

where "detailstream" is:

public class detailstream {     public string id { get; set; }     public datetime date { get; set; }     public int countinfo { get; set; }     public statestream stateinput { get; set; }     public statestream stateoutput { get; set; }     //... }  public enum statestream {     inprogress,     received,     declined,     inexistent } 

so detailstream result of specific stream in specific day. details list of detailstream, ie results of specific stream in specific week.

with name , type there no problems, not know how manage list of detailstream. can me?

this current implementation:

my web service:

[servicecontract] public interface imyservice {     [operationcontract]     [webinvoke(         method = "post",         responseformat = webmessageformat.json)]     standardresponse<streamoutputdto> getstream(string request); }   [aspnetcompatibilityrequirements(requirementsmode = aspnetcompatibilityrequirementsmode.required)] [messageloggingbehavior] public class myservice : imyservice {      public standardresponse<streamoutputdto> getstream(string request)     {         // test case:         standardresponse<streamoutputdto> response = new standardresponse<streamoutputdto>();         response.output = new streamoutputdto();         response.output.name = "hi!";         response.output.type = "input";         response.output.details = new list<detailstream>();          response.output.details.add(new detailstream(){                 id = "1",                 countinfo = 100,                 date = datetime.today });              response.output.details.add(new detailstream(){                 id = "2",                 countinfo = 200 });          return response;     }  } 

my webform.aspx:

<head>     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>     <script src="radgridparser.js"></script> </head>  <body>      <telerik:radscriptmanager runat="server" id="radscriptmanager1" />     <telerik:radskinmanager id="radskinmanager1" runat="server" showchooser="true"/>      <telerik:radgrid id="radgrid1" rendermode="lightweight" clientdatasourceid="radclientdatasource1"               allowpaging="false" allowsorting="false" allowfilteringbycolumn="false" pagesize="5" runat="server">          <mastertableview datakeynames="name" clientdatakeynames="name">             <columns>                 <telerik:gridboundcolumn datafield="name" headertext="" datatype="system.string" >                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="type" headertext="tipologia flusso" datatype="system.string">                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="day1" headertext="lunedì">                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="day2" headertext="martedì">                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="day3" headertext="mercoledì">                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="day4" headertext="giovedì">                 </telerik:gridboundcolumn>                 <telerik:gridboundcolumn datafield="day5" headertext="venerdì">                 </telerik:gridboundcolumn>             </columns>         </mastertableview>      </telerik:radgrid>      <telerik:radclientdatasource id="radclientdatasource1" runat="server" allowbatchoperations="true">         <clientevents oncustomparameter="parametermap" ondataparse="parse" />         <datasource>             <webservicedatasourcesettings>                 <select url="http://soldev/axa.sol.web/ws/ivass/ivassservice.svc/getstream" datatype="json" requesttype="post" />             </webservicedatasourcesettings>         </datasource>         <schema responsetype="json">             <model id="streammodel">                 <telerik:clientdatasourcemodelfield fieldname="name" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="type" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="day1" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="day2" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="day3" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="day4" datatype="string" />                 <telerik:clientdatasourcemodelfield fieldname="day5" datatype="string" />             </model>         </schema>     </telerik:radclientdatasource>  </body> 

my radgridparser.js:

//<![cdata[ function parametermap(sender, args) {     //if want send parameter select call can modify if      //statement check whether request type 'read':     //if (args.get_type() == "read" && args.get_data()) {     if (args.get_type() != "read" && args.get_data()) {         args.set_parameterformat({ request: kendo.stringify(args.get_data().models) });     } }  function parse(sender, args) {     var response = args.get_response();     if (response) {         args.set_parseddata(response.output);     } }  function useraction(sender, args) {     if (sender.get_batcheditingmanager().haschanges(sender.get_mastertableview()) &&                 !confirm("any changes cleared. sure want perform action?")) {         args.set_cancel(true);     } }  //]]> 

radgrid can't handle out of box. thing can think use templatecolumn. template column has "itemtemplate", "inserttemplate", , "edittemplate".

you can put controls , html elements inside container. can access controls (and data item) inside "itemdatabound" event of grid. should achive scenario.

references: template columns

item-databound event:

protected void radgrid_itemdatabound(object sender, griditemeventargs e) {  if (e.item griddataitem)  {   griddataitem griditem = e.item griddataitem;   dynamic dataitem = (yourtype)(griditem.dataitem);   griditem.tooltip = dataitem.id + " - " + dataitem.uuid;  } } 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -