Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
bind database data to infragistics grid
posted

Hiiii,

I am facing trouble to binding database data to infragistics grid in asp.net mvc.

if anyone have some samples related to it please provide me, I am new to this infragistics controls.

Thanks

varun

  • 20255
    Suggested Answer
    Offline posted

    Hello,

    Thank you for contacting us.

    I have created a sample for you in order to show you how to get data from a database. In the .zip you will find a backup file, just restore it (with Microsoft Sql Management Studio) and make te necesary changes to the webconfig in order to have a correct connection string.

     

    1. <add name="IFRScorecardContext" connectionString="Data Source=IGBGSOFDS54;Initial Catalog=IFR_Test;Integrated Security=True;MultipleActiveResultSets=True" providerName="System.Data.SqlClient" />

     

    Code snippet (View):

    1. <script type="text/javascript">
    2.         $(function () {
    3.             $.ajax({
    4.                 type: "POST",
    5.                 url: ' @Url.Action( "GetProjects" , "Projects" ) ',
    6.                 contentType: 'application/json; charset=utf-8',
    7.                 dataType: 'json',
    8.                 data: '{}',
    9.                 success: function (data) {
    10.                     $("#projects").igGrid({
    11.                         autoGenerateColumns: true,
    12.                         autofitLastColumn: false,
    13.                         width: "100%",
    14.                         dataSourceType: "json",
    15.                         responseContentType: "application/json; charset=utf-8",
    16.                         dataSource: data,
    17.                         columns: [
    18.                             { headerText: "Submit Date", key: "IFRSubmittalDate", dataType: "date", width: "10%" },
    19.                             { headerText: "Status", key: "ProjectStatus", dataType: "string", width: "20%" },
    20.                             { headerText: "PVID", key: "PVID", dataType: "number", width: "10%" },
    21.                             { headerText: "WO#", key: "WorkOrder", dataType: "number", width: "10%" },
    22.                             { headerText: "Type", key: "ReqType", dataType: "string", width: "10%" },
    23.                             { headerText: "OPCO", key: "OperatingCompany", dataType: "string", width: "10%" },
    24.                             { headerText: "Station", key: "Station", dataType: "string", width: "20%" }
    25.                         ],
    26.                         features: [
    27.                             {
    28.                                 name: 'Sorting'
    29.                             },
    30.                             {
    31.                                 name: 'Tooltips'
    32.                             },
    33.                             {
    34.                                 name: 'Selection'
    35.                             },
    36.                             {
    37.                                 name: 'Filtering'
    38.                             },
    39.                             {
    40.                                 name: 'Paging'
    41.                             },
    42.                             {
    43.                                 name: 'Resizing'
    44.                             },
    45.                             {
    46.                                 name: 'ColumnMoving'
    47.                             }
    48.                         ]
    49.                     });
    50.                 }
    51.             });
    52.         });
    53.     </script>

     Code snippet (Controller):

    1. public ActionResult Index()
    2.         {
    3.             return View();
    4.         }
    5.  
    6.         
    7.         public JsonResult GetProjects()
    8.         {
    9.                 var data = db.Projects.Select(x => new
    10.                 {
    11.                     x.IFRSubmittalDate,
    12.                     x.ProjectStatus,
    13.                     x.PVID,
    14.                     x.WorkOrder,
    15.                     x.ReqType,
    16.                     x.OperatingCompany,
    17.                     x.Station
    18.                 })
    19.                     .Where(p => p.ProjectStatus == "Sent for Review" || p.ProjectStatus == "Under Review").ToList();
    20.  
    21.  
    22.                 //string data = new JavaScriptSerializer().Serialize(projects);
    23.                 if (data != null)
    24.                 {
    25.                     return new JsonResult() { Data = data, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    26.                 }
    27.                 return new JsonResult() { Data = new object[]{}, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
    28.         }

     

    Code snippet (Model):

     

    1. public partial class Project
    2.     {
    3.  
    4.  
    5.         public int ProjectID { get; set; }
    6.         public string Station { get; set; }
    7.         [Display(Name="OPCO")]
    8.         public string OperatingCompany { get; set; }
    9.         [Display(Name="Proj Desc")]
    10.         public string ProjectDescription { get; set; }
    11.         public int PVID { get; set; }
    12.         [Display(Name="WO#")]
    13.         public string WorkOrder { get; set; }
    14.         [Display(Name = "AEP Lead")]
    15.         public string AEPLead { get; set; }
    16.         [Display(Name = "OEC Company")]
    17.         public string OECCompany { get; set; }
    18.         [Display(Name = "OEC Location")]
    19.         public string OECTeamLocation { get; set; }
    20.         [Display(Name = "OEC Engineer")]
    21.         public string OECEngineer { get; set; }
    22.         [Display(Name = "OEC Engineer's AEP Experience (years)")]
    23.         public int OECEngAEPExperience { get; set; }
    24.         [Display(Name = "OEC Engineer's Experience (years)")]
    25.         public int OECEngOverallExperience { get; set; }
    26.         [Display(Name = "OEC Peer Reviewer")]
    27.         public string OECPeerReviewer { get; set; }
    28.         [Display(Name = "OEC Peer Reviewer's AEP Experience (years)")]
    29.         public int OECPeerAEPExperience { get; set; }
    30.         [Display(Name = "OEC Peer Reviewer's Experience (years)")]
    31.         public int OECPeerOverallExperience { get; set; }
    32.         [Display(Name = "OEC QA Completed?")]
    33.         public string QACompleted { get; set; }
    34.         [Display(Name = "IFR Submittal Date")]
    35.         [DataType(DataType.Date)]
    36.         public System.DateTime IFRSubmittalDate { get; set; }
    37.         [Display(Name = "AEP's IFR Return Date")]
    38.         [DataType(DataType.Date)]
    39.         public System.DateTime AEPIFRReturnDate { get; set; }
    40.         [Display(Name = "IFC Submittal Date")]
    41.         [DataType(DataType.Date)]
    42.         public System.DateTime IFCSubmittalDate { get; set; }
    43.         [Display(Name = "ProjectWise IFR Folder URL")]
    44.         public string ProjectwiseIFRFolderURL { get; set; }
    45.         [Display(Name = "IFR Status")]
    46.         public string ProjectStatus { get; set; }
    47.         [Display(Name = "IFR Type")]
    48.         public string ReqType { get; set; }
    49.     }

     

    TransmissionIFRTest.zip
  • 20255
    Offline posted

    If I may be of further assistance do not hesitate to contact me.