データベースからデータを取得して、型競合のインスタンスを作成しました。関数selectCompetitionByIdは、1行のデータを返します。
Competition competition = BLLc.selectCompetitionById(competitionId);
このインスタンスのアイテムを自分のページに表示するにはどうすればよいですか?(リピーターは動作しません)
DetailsView
自動生成されたフォームを作成する場合は、 :を使用できます。
<asp:DetailsView ID="competitionDetails" RunAt="Server" AutoGenerateColumns="true" />
データソースとしてダミー配列(1つのアイテムのみ)を作成します。
competitionDetails.DataSource = new Competition[] { competition };
もう1つの方法は、オブジェクトを参照する標準のHTMLテンプレートを使用することです。最初にページのプロパティにします。
<script runat="Server">
public Competition competition { get; set; }
void Page_Load()
{
competition = BLLc.selectCompetitionById(competitionId);;
this.DataBind();
}
</script>
次に、必要に応じてマークアップで参照します。
<div>
<span>Title</span>
</div>
<div>
<span><%# competition.Title %></span>
</div>
<div> etc ... </div>