(ファイル )を指定しSelectCommand
ました。このクエリは、 に示すデータを返します。SqlDataSource
.aspx
SelectCommand
GridView
現在id
、select コマンドには (Primary Key) という名前のプロパティが 1 つありますが、そのデータは に表示されません。それぞれがクリックGridView
されたときに、この「id」を別のページに送信したいと考えています。ButtonField
上の画像は を示していますGridView
。各列はアクティビティ フィールドを表し、各行は固有のアクティビティを表します。最後の列にはButtonFields
、アクティビティへの登録があります。
クリックされた行の 'id' とともに学生をアクティビティ ページに登録するように送りたいです。「id」の値は に表示されませんGridView
。
それを達成するための良い方法を教えてください。
バックエンド (.cs) ファイルの 'id' の値にアクセスし、ButtonField コマンドを介して id の値を送信することが 1 つの解決策になると思います。しかし、.csファイルでアクセスできるかどうかわかりませんか?
ASPX コード:
<asp:GridView ID="ShowActivitiesGridView" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="name" HeaderText="Name" SortExpression="name" />
<asp:BoundField DataField="location" HeaderText="Location" SortExpression="location" />
<asp:BoundField DataField="date_of_activity" HeaderText="Date of Activity" SortExpression="date_of_activity" />
<asp:BoundField DataField="organization" HeaderText="Organization" SortExpression="organization" />
<asp:BoundField DataField="no_of_student" HeaderText="No of Student" SortExpression="no_of_student" />
<asp:BoundField DataField="description" HeaderText="Description" SortExpression="description" />
<asp:ButtonField CommandName="RowCommand" HeaderText="Register For Activity" ShowHeader="True" Text="Register" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT [id], [name], [location], [date_of_activity], [organization], [no_of_student], [description] FROM [Activities]">
</asp:SqlDataSource>