asp.net listview showing data from related entity and changing it -


I am using the Entity Framework. The unit of my model is tblGameInfo, where there are tblPlayer1 and tblPlayer2 in navigation properties, which are related to the unit TBplayer. I have a list view on my page, where I want to show the game information along with the names of the players. I have found that in the list view I should have an example:

  & lt; Td> & Lt; Asp: Label ID = "tblPlayer1Label" runat = "server" text = '& lt;% # Eval ("tblplayer1.FirstName")% & gt; / & Gt; & Lt; / TD & gt; & Lt; TD & gt; & Lt; Asp: label id = "tblPlayer2Label" runat = "server" text = '& lt;% # gate name (Eval ("tblplayer2.id")) & gt; / & Gt; & Lt; / TD & gt;  

But this does not work, I did not find anything in a list view. I have tried many different options but one is not able to do some work, maybe some simple mistake but I am new to asp.net and can not get it. The second problem with it is editing dropdown list with all the players in the editing template.

& lt; Td> & Lt; Asp: DropDownList ID = "DropDownList1" runat = "server" dataTapText = "FullName" DataValueField = "id" SelectedValue = '& lt;% # Bind ("tblplayer2")% & gt; & Gt; & Lt; - ?? & Lt; / ASP: DropDownList & gt; & Lt; / TD & gt;

How do I know it? Are not binding and changing properties? It writes to me that element is not present in a list of elements.

Try the following:

  text = '& lt;% # GetPlayerName (but MyObjectType) Eval (("tblPlayer2"). ID)%> '/ & Gt;  

There may be an extra), but basically get player 2 references and then the ID. Also, with EF, you have to load all the related objects before using them, so make sure that its navigation properties are loaded when the object is bound.

Finally, for the drop down list, you must enter the reference and see the player's ID, which you can get from your updated sample.

HTH


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -