Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# gridview中的选定行_C#_Asp.net_Sql Server 2008_Gridview - Fatal编程技术网

C# gridview中的选定行

C# gridview中的选定行,c#,asp.net,sql-server-2008,gridview,C#,Asp.net,Sql Server 2008,Gridview,我在SQLServer中有两个表,如下所示 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"

我在SQLServer中有两个表,如下所示

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>
因此,在单击事件时,我想将所选行
patientid
以及
button text value=“formatric3d”
插入表名Patexam


这意味着PId等于在gridview上选择的PatientId,检查等于按钮text value=“formatric3d”这是您想要的吗

      <asp:Button runat="server" ID="btnExam" Text="formatric3d" OnClick="Exam_ClickHandler" />
                <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" />
                                <asp:Label runat="server" ID="lblPID" Visible="false" Text='<%# Eval("PatientId") %>'></asp:Label>
                            </ItemTemplate>

                        </asp:TemplateField>
                        <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>

      <h3>Patient Exams</h3>
            <asp:DataList runat="server" ID="dtlExams">
                <ItemTemplate>
                    <%#Eval("Exam") %>
                </ItemTemplate>
            </asp:DataList>
//////////////// tree view 
    <asp:TreeView runat="server" ID="tvExams">
        </asp:TreeView>
////////////////树视图 树烯醇

    foreach (DataRow row in exams.Rows)
    {
        tnnn = new TreeNode(exams["PRODSHORT"].ToString());
        tvExams.Nodes.Add(tnnn);
    }

}

还有一个帮助…现在在检查一行之后…我想查看特定患者的插入数据…这意味着一个patientid可能有多个检查值…因此我想显示所选patientid的所有检查…请告诉我如何使用代码。谢谢你,当然。您需要添加另一个数据绑定控件,如gridview来显示数据。如果我想在treeview中显示,那么代码应该是什么样的?谢谢,我已经编辑了我的答案。。像这样的事情会对你有用的。如果这对你有效,请投票。快乐编程:像这样的pye…但我想在树状视图中显示,所以它将如何成为可能?
  protected void Exam_ClickHandler(object sender, EventArgs e)
    {
        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;

                ///your insertion query goes here.
                ///

                GetPatientExams(patientId);
            }

        }
    }

    protected void Patient_ExamHandler(object sender, CommandEventArgs e)
    {
        string patientId = e.CommandArgument.ToString();
        GetPatientExams(patientId);


    }



  private void GetPatientExams(string pid)
{

    DataTable exams = "Get exam data from db by pid";

    dtlExams.DataSource = exams;
    dtlExams.DataBind();
    foreach (DataRow row in exams.Rows)
    {
        tnnn = new TreeNode(exams["PRODSHORT"].ToString());
        tvExams.Nodes.Add(tnnn);
    }

}