0

以下のように、1つのページにグリッドビューがあります。

 <asp:GridView ID="gvDoctorList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
                            AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:CheckBox runat="server" ID="chk" OnCheckedChanged="chk_CheckedChanged" />
                                        <asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'></asp:Label>
                                    </ItemTemplate>

                                </asp:TemplateField>

                                <asp:BoundField DataField="PatientId" HeaderText="PatientId" SortExpression="PatientId" />
                                <asp:BoundField DataField="firstname" HeaderText="firstname" SortExpression="firstname" />
                                <asp:BoundField DataField="lastname" HeaderText="lastname" SortExpression="lastname" />

                                <asp:BoundField DataField="sex" HeaderText="sex" SortExpression="sex" />

                            </Columns>
                        </asp:GridView>
                        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" 
                            SelectCommand="SELECT [PatientId],[firstname], [lastname], [sex] FROM [PatientDetails]"></asp:SqlDataSource>

ユーザーがチェックボックスを同時にオンにすると、グリッドビューから別のページにPatientIdが必要になり、さらにPatientIdをSQLテーブルに挿入したいと考えています。

誰かが私にコードをくれたらどうもありがとう

*更新:: *

私のpage_loadコードは

if (!IsPostBack) { 
foreach (GridViewRow row in gvDoctorList.Rows)
 { 
   CheckBox chk = (CheckBox)row.FindControl("chk"); 
   if (chk.Checked) 
    { 
     string patientId = ((Label)row.FindControl("lblPID")).Text; 
     string exam = ((Button)sender).Text; 
     Session[patientId] = patientId;
     }
  }
 }
4

1 に答える 1