Hey Guys! ive been stuggling with this for a while

I Have a Datagrid and a few comboboxes the one combobox should populate the Grid when an Item is selected
I debugged my code , and it seemd that all the correct data is being pulled through but i keep getting an empty Grid!!
Can someone please go through my code , maybe i just missed something

Thanks

-CSS-

<asp:DataGrid ID="dtgDealsEdit" runat="server" CssClass="grid" AutoGenerateColumns="False"
                                Style="border-top-left-radius: 5px; border-top-right-radius: 5px; background-color: White; padding: 0px;">
                                <AlternatingItemStyle CssClass="gridViewRowAlternating" />
                                <HeaderStyle CssClass="DataGridFixedHeader" Height="40px"></HeaderStyle>
                                <Columns>
                                 <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblCaseCodeHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Case Code"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblCaseCode" CssClass="gridLabels" Width="50px" runat="server" Text='<%# Eval("CaseCode") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Right" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblUnitCodeHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Unit Code"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblUnitCode" CssClass="gridLabels" Width="50px" runat="server" Text='<%# Eval("UnitCode") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Right" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblCasePriceHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Cash Price"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtCasePrice" CssClass="gridTextBox" Width="50px" runat="server"
                                                onchange="return addCommas(this.value)"></asp:TextBox>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Left" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblCategoryHeader" CssClass="gridLabels" Width="100px" runat="server" Text="Category"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblCategory" CssClass="gridLabels" Width="100px" runat="server" Text='<%# Eval("Category") %>'></asp:Label>
                                            <asp:Label ID="lblCategoryID_FK" CssClass="gridLabels" Width="100px" runat="server" Visible="false" Text='<%# Bind("CategoryID_FK") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="100px" HorizontalAlign="Left" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblProductHeader" CssClass="gridLabels" Width="150px" runat="server" Text="Product"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblProduct" CssClass="gridLabels" Width="150px" runat="server" Text='<%# Eval("ProductDescription") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="150px" HorizontalAlign="Left" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblPacksizeHeader" CssClass="gridLabels" Width="45px" runat="server" Text="Packet Size"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblPacksize" CssClass="gridLabels" Width="45px" runat="server" Text='<%# Eval("PackSize") %>'></asp:Label>
                                        </ItemTemplate>
                                        <ItemStyle Width="45px" HorizontalAlign="Left" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblExclusivePriceHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Exclusive Price"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtExclusivePrice" Text='<%# Eval("Exclusive Price") %>' CssClass="gridTextBox" Width="50px" runat="server"
                                                onchange="return addCommas(this.value)"></asp:TextBox>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Right" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblSUGGHeader" CssClass="gridLabels" Width="50px" runat="server" Text="SUGG RSP"></asp:Label>
                                    </HeaderTemplate>

                                        <ItemTemplate>
                                            <asp:TextBox ID="txtSUGG" Text='<%# Eval("SUGG") %>' CssClass="gridTextBox"  Width="50px" runat="server" onchange="return addCommas(this.value)"></asp:TextBox>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Right" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblVolumeHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Volume"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtVolume" Text='<%# Eval("VolumeSpike") %>' CssClass="gridTextBox" Width="50px" runat="server" onchange="return addCommas(this.value)"></asp:TextBox>
                                        </ItemTemplate>
                                        <ItemStyle Width="50px" HorizontalAlign="Right" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>
                                    <asp:TemplateColumn>
                                        <HeaderTemplate>
                                        <asp:Label ID="lblCommentsHeader" CssClass="gridLabels" Width="50px" runat="server" Text="Comments"></asp:Label>
                                    </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtComments"  Text='<%# Bind("Comments") %>' CssClass="gridTextBox" Width="100px" runat="server"
                                                TextMode="MultiLine"></asp:TextBox>
                                        </ItemTemplate>
                                        <ItemStyle Width="100px" HorizontalAlign="Left" Font-Size="Small" CssClass="dtgDealstrtdStyle"/>
                                    </asp:TemplateColumn>

                                </Columns>
                </asp:DataGrid>

-CodeBehind-

public void PopulateGridData(int intDealsID)
    {
        clsDeals clsDeals = new clsDeals();



    using (DealsDatabaseEntities DealsDB = new DealsDatabaseEntities())
    {
        try
        {
            List<DealsGetEdit_Result> lstDealsedit = DealsDB.DealsGetEdit(intDealsID).ToList();
            if (lstDealsedit.Count > 0)
            {
                dtgDealsEdit.DataSource = FillInGrid("CaseCode", "UnitCode", "Category", "ProductDescription", "PackSize", "Exclusive Price", "SUGG", "VolumeSpike", "Comments");
                dtgDealsEdit.DataBind();
                dtgDeals.Visible = false;

            }
        }
        catch (Exception ex)
        {
            throw;
        }
        finally
        {
            DealsDB.Dispose();
        }
    }
}



public DataTable FillInGrid(String strCol1, String strCol2, String strCol4, String strCol5, String strCol6, String strCol7, String strCol8, String strCol9, String strCol10)
    {
        Int32 cnt = 0;

        int intDealsID = (Convert.ToInt32(CmbExist.SelectedValue));

        using (DealsDatabaseEntities DealsDB = new DealsDatabaseEntities())
        {
            List<DealsGetEdit_Result> lstDealsedit = DealsDB.DealsGetEdit(intDealsID).ToList();

            DataTable dt = new DataTable();

            dt.Columns.Add(strCol1);
            dt.Columns.Add(strCol2);
            dt.Columns.Add(strCol4);
            dt.Columns.Add(strCol5);
            dt.Columns.Add(strCol6);
            dt.Columns.Add(strCol7);
            dt.Columns.Add(strCol8);
            dt.Columns.Add(strCol9);
            dt.Columns.Add(strCol10);


            Int32 totalRows = Convert.ToInt32(Decimal.Ceiling(Decimal.Divide(cnt, 13)));
            totalRows = (totalRows == 0) ? 13 : totalRows * 13;

            for (int x = 0; x != totalRows; x++)
            {
                dt.Rows.Add();
                dt.Rows[x][strCol1] = (cnt > x) ? lstDealsedit[x].CaseCode.ToString() : "";
                dt.Rows[x][strCol2] = (cnt > x) ? lstDealsedit[x].UnitCode.ToString() : "";
                dt.Rows[x][strCol4] = (cnt > x) ? lstDealsedit[x].Category.ToString() : "";
                dt.Rows[x][strCol5] = (cnt > x) ? lstDealsedit[x].ProductDescription.ToString() : "";
                dt.Rows[x][strCol6] = (cnt > x) ? lstDealsedit[x].PackSize.ToString() : "";
                dt.Rows[x][strCol7] = (cnt > x) ? lstDealsedit[x].Exclusive_Price.ToString() : "";
                dt.Rows[x][strCol8] = (cnt > x) ? lstDealsedit[x].SUGG.ToString() : "";
                dt.Rows[x][strCol9] = (cnt > x) ? lstDealsedit[x].VolumeSpike.ToString() : "";
                dt.Rows[x][strCol10] = (cnt > x) ? lstDealsedit[x].Comments.ToString() : "";
            }

            return dt;
        }

Recommended Answers

All 2 Replies

After selecting from the dropdown, are you rebinding the grid? Should happen on the selectedIndexChange event.

Ggamble is right as the datagrid is populated after selecting the dropdown box. Your datagrid should populate within the selectedindexchange event of dropdownbox.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.