更改页脚下拉列表时Gridview结构出现故障

时间:2017-11-30 12:22:52

标签: c# html asp.net gridview

我有一个gridview,显示"没有找到结果"当空时,用页脚添加新行。这部分显示正常。 no result image

我已经为无结果实现了以下功能。

private void ShowNoResultFound(DataTable dt, GridView gv)
    {
        dt.Rows.Add(dt.NewRow()); // create a new blank row to the DataTable
                                  // Bind the DataTable which contain a blank row to the GridView
        gv.DataSource = dt;            
        gv.DataBind();
        // Get the total number of columns in the GridView to know what the Column Span should be
        int columnsCount = gv.Columns.Count;
        gv.Rows[0].Cells.Clear();// clear all the cells in the row
        gv.Rows[0].Cells.Add(new TableCell()); //add a new blank cell
        gv.Rows[0].Cells[0].ColumnSpan = columnsCount; //set the column span to the new added cell
        //You can set the styles here
        gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
        gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
        gv.Rows[0].Cells[0].Font.Bold = true;
        //set No Results found to the new added cell
        gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";            
    }  

当我更改下拉列表索引时,会触发下面的代码

protected void fddlItemDesc_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList fddlItem = (DropDownList)GVInvoiceDet.FooterRow.FindControl("fddlItemDesc");
        TextBox hsnCode = (TextBox)GVInvoiceDet.FooterRow.FindControl("txtItemHSN");
        HiddenField hdnFtItemGST = (HiddenField)GVInvoiceDet.FooterRow.FindControl("hdnFooterItemGST");
        TextBox itemCode = (TextBox)GVInvoiceDet.FooterRow.FindControl("txtItemCode");
        TextBox unitValue = (TextBox)GVInvoiceDet.FooterRow.FindControl("txtItemUnitValue");
        TextBox unitRate = (TextBox)GVInvoiceDet.FooterRow.FindControl("txtItemUnitRate");
        if (fddlItem.SelectedIndex == 0)
        {
            itemCode.Text = "";
            hsnCode.Text = "";
            hdnFtItemGST.Value = "";
            unitRate.Text = "";
            unitValue.Text = "";
        }
        else
        {
            hsnCode.Text = fddlItem.SelectedValue.Split('-')[1];
            itemCode.Text = fddlItem.SelectedValue.Split('-')[0];
            hdnFtItemGST.Value = fddlItem.SelectedValue.Split('-')[2];
            unitRate.Text = fddlItem.SelectedValue.Split('-')[3];
            unitValue.Text = unitRate.Text;              
        }          
    }

问题是第一排的colspan受到干扰。 Colspan位于第一个细胞中,但其他细胞也如图所示添加:

enter image description here

HTML code(aspx)

<asp:GridView ID="GVInvoiceDet" runat="server" Width="100%" AutoGenerateColumns="False" 
        HorizontalAlign="Left" BorderStyle="Outset" OnRowCancelingEdit="GVInvoiceDet_RowCancelingEdit"
        OnRowEditing="GVInvoiceDet_RowEditing" OnRowDataBound="GVInvoiceDet_RowDataBound" ShowFooter="True"
        OnRowCommand="GVInvoiceDet_RowCommand" OnRowUpdating="GVInvoiceDet_RowUpdating"
        OnRowDeleting="GVInvoiceDet_RowDeleting" OnRowDeleted="GVInvoiceDet_RowDeleted" OnDataBound="GVInvoiceDet_OnDataBound" 
        OnRowUpdated="GVInvoiceDet_RowUpdated" AllowSorting="True" DataKeyNames="invoiceno,itemcd" ShowHeaderWhenEmpty="true">
        <HeaderStyle BackColor="#0000ff" ForeColor="Yellow" />
        <FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
        <EditRowStyle BackColor="#000000" ForeColor="Red" />
        <AlternatingRowStyle BackColor="#FE9CD5" />

        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <a href="javascript:expandcollapse('div<%# Eval("itemcd") %>', 'one');">
                        <img id="imgdiv<%# Eval("itemcd") %>" alt="Click to show/hide Tax Details <%# Eval("itemcd") %>" border="0" src="Images/plus.png" />
                    </a>
                </ItemTemplate>
                <ItemStyle HorizontalAlign="Left" Width="15px" />
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="10%" HeaderText="Item Code" SortExpression="itemcd">
                <ItemTemplate>
                    <asp:Label ID="lblItemCode" runat="server" Text='<%# Eval("itemcd")%>'></asp:Label>
                </ItemTemplate>

                <FooterTemplate>
                    <asp:TextBox ID="txtItemCode" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="10%" HeaderText="HSN Code" SortExpression="hsncd">
                <ItemTemplate>
                    <asp:Label ID="lblItemHSNCode" runat="server" Text='<%# Eval("hsncd")%>'></asp:Label><asp:HiddenField ID="hdnItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
                </ItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtItemHSN" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox><asp:HiddenField ID="hdnFooterItemGST" runat="server" Value='<%# Eval("itempercentage") %>' />
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="30%" HeaderText="Item Description" SortExpression="itemdesc">
                <ItemTemplate>
                    <asp:Label ID="lblItemDesc" runat="server" Text='<%# Eval("itemdesc")%>'></asp:Label>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:DropDownList ID="fddlItemDesc" runat="server" AutoPostBack="true" OnSelectedIndexChanged="fddlItemDesc_SelectedIndexChanged"></asp:DropDownList>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="6%" HeaderText="Quantity">
                <ItemTemplate>
                    <asp:Label ID="lblItemQty" runat="server" Text='<%# Eval("quantity")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtItemQty" Width="90%" runat="server" Text='<%# Bind("quantity")%>' OnTextChanged="calculateFinalValue" AutoPostBack="true"></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtItemQty" Width="90%" MaxLength="100" runat="server" OnTextChanged="calculateFinalValue" AutoPostBack="true"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="8%" HeaderText="Unit Rate">
                <ItemTemplate>
                    <asp:Label ID="lblItemUnitRate" runat="server" Text='<%# Eval("unitrate")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtItemUnitRate" Width="90%" runat="server" Text='<%# Bind("unitrate")%>' ></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtItemUnitRate" Width="90%" MaxLength="100" runat="server" ></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="7%" HeaderText="Unit Value">
                <ItemTemplate>
                    <asp:Label ID="lblItemUnitValue" runat="server" Text='<%# Eval("unitvalue")%>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtItemUnitValue" Width="90%" runat="server" Text='<%# Bind("unitvalue")%>' Enabled="false" OnTextChanged="calculateFinalValue" AutoPostBack="true"></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtItemUnitValue" Width="90%" MaxLength="100" runat="server" Enabled="false" OnTextChanged="calculateFinalValue" AutoPostBack="true"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField ItemStyle-Width="10%" HeaderText="Final Value">
                <ItemTemplate>
                    <asp:Label ID="lblItemFinalValue" runat="server" Text=''></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtItemFinalValue" Width="90%" runat="server" Text='' Enabled="false"></asp:TextBox>
                </EditItemTemplate>
                <FooterTemplate>
                    <asp:TextBox ID="txtItemFinalValue" Width="90%" MaxLength="100" runat="server" Enabled="false"></asp:TextBox>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" HeaderText="Edit" ItemStyle-Width="7%" />
            <asp:TemplateField HeaderText="Delete" ItemStyle-Width="8%">
                <ItemTemplate>
                    <asp:LinkButton ID="linkDeleteInvoiceItem" CommandName="DeleteItem" runat="server">Delete</asp:LinkButton>
                </ItemTemplate>
                <FooterTemplate>
                    <asp:LinkButton ID="linkAddInvoiceItem" CommandName="AddItem" runat="server">Add</asp:LinkButton>
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <tr>
                        <td colspan="100%">
                            <div id="div<%# Eval("itemcd") %>" style="display: none; position: relative; left: 15px; overflow: auto; width: 97%">
                                <asp:GridView ID="GVTaxDetails" BackColor="White" Width="100%" Font-Size="Small" AutoGenerateColumns="false"
                                    runat="server" DataKeyNames="invoiceno,itemcd,gstPer" ShowFooter="True" OnRowUpdating="GVTaxDetails_RowUpdating"
                                    OnRowCommand="GVTaxDetails_RowCommand" OnRowEditing="GVTaxDetails_RowEditing" GridLines="None"
                                    OnRowUpdated="GVTaxDetails_RowUpdated" OnRowCancelingEdit="GVTaxDetails_CancelingEdit"
                                    OnRowDataBound="GVTaxDetails_RowDataBound" OnRowDeleting="GVTaxDetails_RowDeleting" OnRowDeleted="GVTaxDetails_RowDeleted"
                                    ShowHeaderWhenEmpty="true" BorderStyle="Double" BorderColor="#0083C1" >
                                    <RowStyle BackColor="Gainsboro" />
                                    <AlternatingRowStyle BackColor="White" />
                                    <HeaderStyle BackColor="#0083C1" ForeColor="White" />
                                    <FooterStyle BackColor="White" />
                                    <EditRowStyle BackColor="#000000" ForeColor="Red" />
                                    <Columns>
                                        <asp:TemplateField ItemStyle-Width="5%" HeaderText="SL No">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxSlno" runat="server" Text='<%# Eval("slno")%>'></asp:Label>
                                                <asp:HiddenField ID="hdnViewTaxItemCd" runat="server" Value='<%# Eval("itemcd") %>' />
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtViewTaxSlno" runat="server" Text='<%# Eval("slno")%>' Enabled="false"></asp:TextBox>
                                                <asp:HiddenField ID="hdnViewTaxItemCd" runat="server" Value='<%# Eval("itemcd") %>' />
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtViewTaxSlno" MaxLength="3" Width="80%" runat="server" Text='' Enabled="false"></asp:TextBox>
                                                <asp:HiddenField ID="hdnViewTaxItemCd" runat="server" Value='<%# Eval("itemcd") %>' />
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="15%" HeaderText="Value">
                                            <ItemTemplate>
                                                <asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
                                                <asp:Label ID="lblViewTaxDesc" runat="server" Text='<%# Eval("valuedesc")%>'></asp:Label>
                                            </ItemTemplate>

                                            <FooterTemplate>
                                                <asp:HiddenField ID="hdnViewTaxDesc" runat="server" Value='<%# Eval("valuecd") %>' />
                                                <asp:DropDownList ID="fddViewTaxDesc" Width="90%" runat="server" AutoPostBack="true" OnSelectedIndexChanged="fddlViewTaxDesc_SelectedIndexChanged"></asp:DropDownList>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="3%" HeaderText="Amount">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtViewTaxAmount" runat="server" Text='<%# Eval("value")%>'></asp:TextBox>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="7%" HeaderText="Ref. Sl No">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxRefNo" runat="server" Text='<%# Eval("refslno")%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtViewTaxRefNo" runat="server" Value='<%# Eval("refslno") %>' />
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtViewTaxRefNo" runat="server" Value='<%# Eval("refslno") %>' />
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="10%" HeaderText="Tax-Mode">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxMode" runat="server" Text='<%# Eval("absper").ToString()=="A"?"Absolute":"Percentage"%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:HiddenField ID="hdnViewTaxMode" runat="server" Value='<%# Eval("absper") %>' />
                                                <asp:DropDownList ID="eddlViewTaxMode" Width="90%" runat="server" AutoPostBack="false">
                                                    <asp:ListItem Value="-1" Text="-Select Mode-"></asp:ListItem>
                                                    <asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
                                                    <asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
                                                </asp:DropDownList>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="fddlViewTaxMode" Width="95%" runat="server" AutoPostBack="false">
                                                    <asp:ListItem Value="-1" Text="-Select Mode-" Selected="True"></asp:ListItem>
                                                    <asp:ListItem Value="A" Text="Absolute"></asp:ListItem>
                                                    <asp:ListItem Value="P" Text="Percentage"></asp:ListItem>
                                                </asp:DropDownList>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="10%" HeaderText="Operation">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxOperation" runat="server" Text='<%# Eval("addsub").ToString()=="A"?"Add":"Subtract"%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:HiddenField ID="hdnViewTaxOperation" runat="server" Value='<%# Eval("addsub") %>' />
                                                <asp:DropDownList ID="eddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
                                                    <asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
                                                    <asp:ListItem Value="A" Text="Add"></asp:ListItem>
                                                    <asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
                                                </asp:DropDownList>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:DropDownList ID="fddlViewTaxOperation" Width="90%" runat="server" AutoPostBack="false">
                                                    <asp:ListItem Value="-1" Text="-Select Operation-" Selected="True"></asp:ListItem>
                                                    <asp:ListItem Value="A" Text="Add"></asp:ListItem>
                                                    <asp:ListItem Value="S" Text="Subtract"></asp:ListItem>
                                                </asp:DropDownList>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:TemplateField ItemStyle-Width="3%" HeaderText="Final Amount">
                                            <ItemTemplate>
                                                <asp:Label ID="lblViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>'></asp:Label>
                                            </ItemTemplate>
                                            <EditItemTemplate>
                                                <asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
                                            </EditItemTemplate>
                                            <FooterTemplate>
                                                <asp:TextBox ID="txtViewTaxFinalAmount" runat="server" Text='<%# Eval("finalvalue")%>' Enabled="false"></asp:TextBox>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                        <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                                        <asp:TemplateField HeaderText="Delete">
                                            <ItemTemplate>
                                                <asp:LinkButton ID="linkDeleteTaxDetails" CommandName="Delete" runat="server" OnClientClick="return confirm('Are you sure you want to delete the Tax entry?')">Delete</asp:LinkButton>
                                            </ItemTemplate>
                                            <FooterTemplate>
                                                <asp:LinkButton ID="linkAddTaxDetails" CommandName="AddTax" runat="server">Add</asp:LinkButton>
                                            </FooterTemplate>
                                        </asp:TemplateField>
                                    </Columns>
                                </asp:GridView>
                            </div>
                        </td>
                    </tr>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="DSItemGrid" runat="server" ConnectionString="<%$ ConnectionStrings:GSTCS %>" ProviderName="<%$ ConnectionStrings:GSTCS.ProviderName %>"
        SelectCommand="select invoiceno, dt.itemcd itemcd, mast.itemdesc itemdesc, mast.hsncd hsncd, dt.quantity quantity, 
        mast.unitrate unitrate, dt.unitvalue unitvalue, mast.itempercentage itempercentage 
        from GSTINVOICEDT dt join GSTITEMMASTER mast on (dt.itemcd = mast.itemcd and dt.unitcode = mast.unitcode and dt.projectcode = mast.projectcode) 
        where dt.unitcode = :unitCode and dt.projectCode = :projCode and dt.invoiceno = :invoiceNo order by invoiceno, itemcd"
        UpdateCommand="UPDATE GSTINVOICEDT set  quantity = :quantity ,unitRate =:unitRate, unitValue=:unitValue 
                        WHERE invoiceno = :invoiceno and unitcode= :unitcode and projectcode = :projectcode and itemcd = :itemcd" EnableViewState="True">
        <SelectParameters>
            <asp:SessionParameter DefaultValue="" Name="unitCode" SessionField="unit" />
            <asp:SessionParameter DefaultValue="" Name="projCode" SessionField="project" />
            <asp:SessionParameter DefaultValue="" Name="invoiceNo" SessionField="invoiceNo" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="quantity" Type="Int32" />
            <asp:Parameter Name="unitRate" Type="Decimal" />
            <asp:Parameter Name="unitValue" Type="Decimal" />
            <asp:Parameter Name="invoiceno" Type="String" />
            <asp:SessionParameter Name="unitcode" SessionField="unit" />
            <asp:SessionParameter Name="projectcode" SessionField="project" />
            <asp:Parameter Name="itemcd" Type="String" />
        </UpdateParameters>
    </asp:SqlDataSource>

0 个答案:

没有答案