Click here to Skip to main content
16,016,425 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, I've currently got two drop down lists and a GridView. The user selects a value in the first drop down list which filters the values in the second drop down list, then the user selects the value in the second drop down list which should in turn populate the GridView based off the two values in the drop down lists.

The drop down lists are working and the second drop down list changes depending on the value of the first. However the gridview is 1. Not showing up on my browser and 2. I presume not populating.

Any help is much appreciated!

C# Code of the selected index change on the DropDownList2
C#
protected void DropDownList2_SelectedIndexChanged(object sener, 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 + "' AND Stock_Take.StockDate = '" + DropDownList1.SelectedValue + "'"), con);
               DataAdapter.Fill(table);
           }

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

       }


Code of my Gridview (Styling taken out) -

ASP.NET
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" AutoGenerateColumns="false" AutoPostBack="True">
                

                <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>


What I have tried:

I have been trying to solve this problem for a while but cannot get any answers.
Posted
Updated 18-Apr-18 2:07am

Try to use Grid View in Update to update content based on other controls.
 
Share this answer
 
can you recheck your code

where Stock_Take.Username = '" + DropDownList1.SelectedValue + "' AND Stock_Take.StockDate = '" + DropDownList1.SelectedValue + "'"



I think the value of Stockdate and username should not be same.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900