c# - output a query column value to a div -
I have a div:
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:
I markup This happens in the code: You want to return more than one record, BTW: do 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 (); }}
div
'runat = "server" `will create:
& lt; Div id = "MyDiv" runat = "server" & gt; & Lt; / Div & gt;
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; }}
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 getProjectByID ()
to must be public static
? I recommend making it either private
or protected
.
Comments
Post a Comment