【发布时间】:2013-10-07 11:50:03
【问题描述】:
我在 sql server 中有两个表如下
PatientDetail - 1st table name
PatientId --- primary key
firstname
lastname
Patexam - 2nd table name
PId ---- foreign key of first table PatientId
Exam
我在页面中有一个gridview,它显示了第一个表的所有列,如下所示
<asp:GridView ID="gvDoctorList" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" AutoGenerateEditButton="true" AutoGenerateDeleteButton="true">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<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>
我有一个按钮,文本值 = "formatric3d" 现在,当我在 gridview 中选择一行,然后单击带有
的按钮value = "formatric3d",
在点击事件时,我想将选定的行 patientid 以及 button text value = "formatric3d" 插入到表名 Patexam 中。
这意味着 PId 等于 PatientId,这是在 gridview 上选择的,而考试等于 button text value = "formatric3d"。
【问题讨论】:
标签: c# asp.net sql-server-2008 gridview