binding a GridView to a List in asp.net c# -
This is the first time that I am doing this, so I need some help,
Behind the code:
list & lt; Truck & gt; FinalistOfftrix = New List & amp; Lt; Truck & gt; (); Public category trucks {public string placa; Public string lock; Public string event; Public date time date; Public string tipcation; Public string person; Public String MissedDate; } Secure Zero btnProcess_Click (Object Sender, EventArgs E) {Trucks Item = New Trucks (); Item.Placa = "MA2323"; item. Lock = "lock 1"; Item.Event = "Event1"; Item.Date = DateTime.Now; Item.TipoCamion = "TRUCK1"; Item.Person = "JULIAN"; Item.MissedDate = ""; FinalListOfTrucks.Add (item); GvOriginal.DataSource = FinalListOfTrucks; GvOriginal.DataBind (); } In Design:
& lt; Asp: button id = "btnprocess" runat = "server" text = "process" onclick = "btnprocess_lick" /> & Lt; ASP: Gridview id = "GVOrinal" runat = "server" & gt; & Lt; / Asp: GridView & gt; But trying to run the web app, I am getting the following error:
Data source for gridview with id 'gvOriginal' No property or properties from which the columns were generated. Make sure your data source has content. Do I have to do something else to do this work?
using properties instead of datings fields Depending on doing, as you got the error message, you can easily change your code so that trucks use properties instead: public class Trucks {public string placa {get; Set; } Public string lock {get; Set; } Public string event {get; Set; } Public Date Time Date {Received; Set; } Public string tucamian {receive; Set; } Public string person {receives; Set; } Public String MissedDate {get; Set; }} If you make this change, then everything should work.
Note that there are many subtle differences between properties and public areas, a property is effectively constructive of the sentences around the statutes, so the public string Placa {get; Set;} Something like this will change: private string_plica; Public String GetPlaca () {Return _placa; } Public Zero SetPlaca (string value) {_placa = value; } For the difference between the methods and fields, this is probably beyond the scope of this question.
Comments
Post a Comment