の後ろに私のC#コードでtxtCourseInfoの値を取得したい私は私の質問から意味あるもののサンプルの例を持っているあなたは可能性リピーターを使用してください:
<asp:repeater id="rptCourses" runat="server" DataSourceID="dsCourseInfo"
<ItemTemplate>
<asp:TextBox ID="txtCourseInfo" Text='<%#Eval("StudentName")#%>' EnableViewState="false" CssClass="dataEntrySearchDataText" ReadOnly="true" runat="server"></asp:TextBox>
</ItemTemplate>
</asp:Repeater>
<asp:sqldatasource id="dsCourseInfo"
ConnectionString="<%$ ConnectionStrings:YourConnectionString %>"
Select Command="Select * from Students">
</asp:sqldatasource>
これですべてのことが可能です。コードの背後からリピーターのコントロールを繰り返して情報を取得することができます。
テキストフィールドにEval
の式があることに注意してください。私は例として、「StudentName」を使用していますが、select statement
追加コメントで返されるカラム名のいずれかを使用する必要があります
- それは多くの点で悪い習慣だ
select * from ...
をしないでください。必要な場合でも、常に必要な列を指定してください。
- 私は、テキストボックスでviewstateを無効にすることを認識します。私はこれを行う理由はわかりませんが、コントロール上で有効にしない限り、情報は後続のポストバックで永続化されないことに注意してください。
UPDATE
はい、あなたはリピーター内部のテーブルを持つことができます。以下の例をご覧ください:
<ItemTemplate>
<table runat="server" style="color: White; background-color: #3A4F63;" visible="false"
id="headerTable">
<tr>
<td colspan="3" align="center">
<asp:Label ID="headerTitle" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td style="width: 200px; background-color: #3A4F63; color: White;">
Image
</td>
<td style="width: 200px;">
Studen Name
</td>
<td style="width: 200px;">
Birth Date
</td>
</tr>
</table>
<table>
<tr>
<td style="width: 200px;">
<asp:Image ID="img" runat="server" ImageUrl='<%#Eval("ImageUrl") %>'></asp:Image>
</td>
<td style="width: 200px;">
<asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
</td>
<td style="width: 200px;">
<asp:Label ID="lblBirthDate" runat="server" Text='<%#Eval("BirthDate") %>'></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
これは、実行時に生徒のリストを表示していますか? –