【发布时间】:2013-10-08 08:29:27
【问题描述】:
我在一页中有一个网格视图,如下所示。
<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>
现在,当用户同时选中复选框时,我希望将来自 gridview 的 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;
}
}
}
【问题讨论】:
-
将该父 ID 放在会话变量中并在下一页使用它/或者您可以在转到另一页时将其作为查询字符串传递:)
-
在页面加载时将会话放在哪里?
-
您可以根据自己的使用情况在任何地方使用使用会话
-
你能检查一下我在页面加载中的代码是否正确?#
-
现在如果我想在另一个页面中显示这些值该怎么办?
标签: c# asp.net gridview sql-server-2012