显示两个网格视图的下拉列表

时间:2018-04-17 09:21:15

标签: c# sql asp.net

我目前有一个下拉列表,在选定的索引更改后,它会根据下拉列表的值在GridView中显示数据。但是,它在现有GridView中显示数据,然后在具有确切信息的现有网格视图旁边显示另一个网格视图。我只是想在现有的open中显示数据。

C#代码:

     protected void DropDownList1_SelectedIndexChanged(object sender, 
     EventArgs e)
    {
        DataTable table = new DataTable();
        using (SqlConnection con = new SqlConnection(@"Data Source= 
         (local)\;Initial Catalog=SmallBatch;Integrated Security=True;"))
        {
            con.Open();
            SqlDataAdapter DataAdapter = new SqlDataAdapter(string.Format("SELECT Item.ItemID, Item.ItemDesc, Stock_Take_Item.BarQuantity, Stock_Take_Item.StorageQuantity FROM Item INNER JOIN Stock_Take_Item ON Item.ItemID = Stock_Take_Item.ItemID INNER JOIN Stock_Take ON Stock_Take_Item.StockTakeIDNew = Stock_Take.StockTakeIDNew where Stock_Take.Username = '" + DropDownList1.SelectedValue + "'"), con);
            DataAdapter.Fill(table);
        }

        GridView1.DataSource = table;
        GridView1.DataBind();

    }
}

现有的Gridview:

<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal">


            <Columns>
                <asp:TemplateField HeaderText="Item ID" HeaderStyle-CssClass="gridview-header">
                    <ItemTemplate>
                        <asp:Label ID="itemIDAdmin" Text='<%# Eval("ItemID")%>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Item Description" HeaderStyle-CssClass="gridview-header">
                    <ItemTemplate>
                        <asp:Label ID="itemDescAdmin" Text='<%# Eval("ItemDesc")%>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Bar Quantity" HeaderStyle-CssClass="gridview-header">
                    <ItemTemplate>
                        <asp:Label ID="barQuantityAdmin" Text='<%# Eval("BarQuantity")%>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

                <asp:TemplateField HeaderText="Storage Quantity" HeaderStyle-CssClass="gridview-header">
                    <ItemTemplate>
                        <asp:Label ID="storageQuantityAdmin" Text='<%# Eval("StorageQuantity")%>' runat="server"></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>

            </Columns>

            </asp:GridView>

0 个答案:

没有答案