c# - output a query column value to a div -


I have a div: and I want to run a query in the database when the page load is loaded from the database to populate with a value. But do not believe how

here is your query in codebehind:.

  public partial class print_request: System.Web.UI.Page {public static object getProjectByID (int id) using {(dbPSREntities11 myEntities = new dbPSREntities11 ()) {var thisProject = myEntities. TbProjects.Where (x => x.ProjectID == ID); Var column = thisProject.Select (x = & gt; new {x.ProjectContactFirstName, x.ProjectContactListName, x.refDepartmentID, x.refAuthSignerID, x.ProjectAccountNum, x.ProjectContactInfo, x.refBuildingID, x.ProjectRoomNum, x.ProjectWorkType, X Project Description, X. Project Manager ID, X. Management Account, X.StartDet, X Project ContactAmil}). Tooltest (); Return column; }} Secure Zero Page_Load (Object Sender, EventArgs E) {string id = Request.QueryString ["id"]. ToString (); GetProjectByID (Convert.ToInt32 (ID)); TxtContactFirstPrint.InnerHtml = getProjectByID.ProjectContactFirstName.ToString (); & Lt; ---- I am doing trial and error, but it is something like that. Hope I'm close ...}}  

Any ideas how do I pop the div with the value from the database? Thanks!

I could change anything I:

getProjectByID () < The / object> object should return a single object or list. In your case I would return an object:

  public static tbProject getProjectByID (int id) (dbPSREntities11 myEntities = using {new dbPSREntities11 ()) {return myEntities.tbProjects.Where (X = & Gt; X.ProjectID == ID) .FirstOrDefault (); }}  

I markup div 'runat = "server" `will create:

  & lt; Div id = "MyDiv" runat = "server" & gt; & Lt; / Div & gt;  

This happens in the code:

  protected void Pej_lod (object sender, EventArgs e) {string id = Request.QueryString [ "id"]. Wire(); Var myResult = getProjectByID (convert toInt32 (id)); If (myResult! = Null) {myDiv.InnerHtml = myResult.ProjectContactFirstName; }}  

You want to return more than one record, getProjectByID () to show & lt; TbProject & gt; . In page_load, you must loop in the list from each tbProject and engage in the string. Attach it up the string after completing the loop

BTW: do getProjectByID () to must be public static ? I recommend making it either private or protected .


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -