Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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# 通过选择GridView1字段打开GridView2_C#_Asp.net_.net - Fatal编程技术网

C# 通过选择GridView1字段打开GridView2

C# 通过选择GridView1字段打开GridView2,c#,asp.net,.net,C#,Asp.net,.net,每次我在GridView1中选择一个特定字段时,它都会在GridView2中打开Access数据库中的相关数据 这是我页面上的代码 <%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="MainView.aspx.vb" Inherits="DosimetryASPNET_WebApplication.MainView" %> <

每次我在GridView1中选择一个特定字段时,它都会在GridView2中打开Access数据库中的相关数据

这是我页面上的代码

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master" CodeBehind="MainView.aspx.vb" Inherits="DosimetryASPNET_WebApplication.MainView" %>


<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>


<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
    <asp:Button ID="btnMenuView" runat="server" Text="Return to Menu" Width="200px" OnClick="btnMenuView_Click" />
    <br />
    <br />

</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder4" runat="server">
    <br />
    <br />

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID">
        <Columns>
            <asp:BoundField DataField="BatchID" HeaderText="BatchID" InsertVisible="False" ReadOnly="True" SortExpression="BatchID" />
            <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
            <asp:BoundField DataField="BatchSize" HeaderText="BatchSize" SortExpression="BatchSize" />
            <asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />
            <asp:BoundField DataField="StartReq" HeaderText="StartReq" SortExpression="StartReq" />
            <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
        </Columns>
    </asp:GridView>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>" ProviderName="<%$ ConnectionStrings:NorthwindConnectionString1.ProviderName %>" SelectCommand="SELECT * FROM [AllBatches]"></asp:SqlDataSource>

    <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID" Visible="False">
    </asp:GridView>

</asp:Content>  
我使用的是Access数据库,对于填充GridView2我使用的是第二个表

对于GridView1,我使用带有以下列的“AllBatches”表: 批次ID-产品-批次大小-优先级-开始状态-

对于GridView2我希望调用表“IngreditStable”。它包含以下列: LotManufactID-成分-实际-目标-最小-最大-称重日期-状态-IDBatchID

在我的Access数据库中,表的工作方式与我希望它在ASP.NET中的工作方式类似。 当我单击“所有批次”的“批次ID”时,它会在我使用“IngreditStable数据单击的行下方的行中打开一个辅助表。 我在银行中创建了两个表之间的关系

这样做可能太复杂了,但我需要帮助开发此功能,至少在GridView2中打开与“所有批次”的“批次ID”相关的“InCreditStable”数据

我希望你已经成功地证明了我的怀疑和清楚。
我在等待帮助。

许多可能的解决方案之一: -在GridView1中声明一个“选择”字段 -定义GridView2列 -当选择字段为Clicks时,将引发onSelectedIndexChanged,在这种情况下,您将读取单击行的BatchID,对配料表执行查询,并在GridView2上显示结果

 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="BatchID" HeaderText="BatchID" InsertVisible="False" ReadOnly="True" SortExpression="BatchID"  />
        <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
        <asp:BoundField DataField="BatchSize" HeaderText="BatchSize" SortExpression="BatchSize" />
        <asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />
        <asp:BoundField DataField="StartReq" HeaderText="StartReq" SortExpression="StartReq" />
        <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
    </Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID" Visible="False">
    <Columns>
        <asp:BoundField DataField="LotManufactID " HeaderText="LotManufactID" SortExpression="LotManufactID" />
        <asp:BoundField DataField="Ingredient " HeaderText="Ingredient" SortExpression="Ingredient" />
        <asp:BoundField DataField="Actual " HeaderText="Actual" SortExpression="Actual" />
        <asp:BoundField DataField="Target " HeaderText="Target" SortExpression="Target" />
        <asp:BoundField DataField="Minimum " HeaderText="Minimum" SortExpression="Minimum" />
        <asp:BoundField DataField="Maximum " HeaderText="Maximum" SortExpression="Maximum" />
        <asp:BoundField DataField="WeighinhDate  " HeaderText="WeighinhDate" SortExpression="WeighinhDate" />
        <asp:BoundField DataField="Status  " HeaderText="Status" SortExpression="Status" />
        <asp:BoundField DataField="IDBatchID " HeaderText="IDBatchID" SortExpression="IDBatchID" />
    </Columns>
</asp:GridView>
 <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="BatchID" HeaderText="BatchID" InsertVisible="False" ReadOnly="True" SortExpression="BatchID"  />
        <asp:BoundField DataField="Product" HeaderText="Product" SortExpression="Product" />
        <asp:BoundField DataField="BatchSize" HeaderText="BatchSize" SortExpression="BatchSize" />
        <asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />
        <asp:BoundField DataField="StartReq" HeaderText="StartReq" SortExpression="StartReq" />
        <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
    </Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="BatchID" Visible="False">
    <Columns>
        <asp:BoundField DataField="LotManufactID " HeaderText="LotManufactID" SortExpression="LotManufactID" />
        <asp:BoundField DataField="Ingredient " HeaderText="Ingredient" SortExpression="Ingredient" />
        <asp:BoundField DataField="Actual " HeaderText="Actual" SortExpression="Actual" />
        <asp:BoundField DataField="Target " HeaderText="Target" SortExpression="Target" />
        <asp:BoundField DataField="Minimum " HeaderText="Minimum" SortExpression="Minimum" />
        <asp:BoundField DataField="Maximum " HeaderText="Maximum" SortExpression="Maximum" />
        <asp:BoundField DataField="WeighinhDate  " HeaderText="WeighinhDate" SortExpression="WeighinhDate" />
        <asp:BoundField DataField="Status  " HeaderText="Status" SortExpression="Status" />
        <asp:BoundField DataField="IDBatchID " HeaderText="IDBatchID" SortExpression="IDBatchID" />
    </Columns>
</asp:GridView>
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
    int BatchID = (int)GridView1.DataKeys[GridView1.SelectedIndex].Value;
    //Access Ingredients with batchID
    var dtIngredients = new DataTable(); // create datasource with a query
    GridView2.Visible = true;
    GridView2.DataSource = dtIngredients;
    GridView2.DataBind();
}