1

我有一个通过数据库填充的 asp gridview 控件(允许分页)。我还允许用户连续编辑任何单元格。gridview 控件被包裹在这个 div 标签中,这使得它更小,占用更少的屏幕。它工作得很好,直到我单击编辑按钮,这导致所选行变成编辑模式。当它这样做时,将编辑行突出显示为一种颜色,并使该行上的控件成为文本框。我为 gridview 中的每一列使用模板。下列的;

TemplateField ItemTemplate EditTemplate FooterTemplate

对于每一列。当gridview 切换到editmode 时,它​​基本上以默认大小呈现网格,该大小占据了所有屏幕并且看起来很糟糕......似乎忽略了div 标签。关于为什么在编辑模式和非编辑模式之间切换渲染大小的任何想法?当我取消编辑操作时,它会在网格的初始负载上恢复到正确的大小:(

4

3 回答 3

1

这可能是编辑模式文本框使您的网格失控。您的 DIV 字体大小仅适用于文本跨度元素,而不适用于文本框。

尝试设置文本框的样式以减小它们的大小。每个链接在这里

<asp:GridView ID="gvCustomer" runat="server">
    ...
    <EditRowStyle CssClass="GridViewEditRow" /> <%-- add this --%>
</asp:GridView>

然后为您的文本框添加样式:

.GridViewEditRow input[type=text] {width:50px;} 

或者,根据可能填充这些框的文本大小,添加 font-size 属性:

.GridViewEditRow input[type=text] {width:70px; font-size: .9em} 
于 2013-02-05T16:38:08.637 回答
0

利用:

< Control style width="" /> between < asp:Boundfield>----< /asp:Boundfield> 

它会立即解决。

于 2013-12-29T17:44:35.557 回答
0
<div align="center" style="font-size: smaller;">
        <table>
            <tr>
                <td>
                    <asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="false" AllowPaging="True"
                        ShowFooter="True" BorderColor="Blue" BorderStyle="Double">
                        <Columns>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="StandardAcctNo" ShowHeader="true">
                                <HeaderTemplate>
                                    Standard<br />
                                    Account
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblStandardAcctNo" runat="server" Text='<%# Bind("StandardAcctNo")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtStandardAcctNo" runat="server" Text='<%# Eval("StandardAcctNo") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:DropDownList ID="FtrddlStandardAcctNo" runat="server">
                                    </asp:DropDownList>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="CompanyID" ShowHeader="true">
                                <HeaderTemplate>
                                    Company<br />
                                    ID
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblCompanyID" runat="server" Text='<%# Bind("CompanyID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCompanyID" runat="server" Text='<%# Eval("CompanyID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="50px" ID="ftrCompanyID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="OrgGroupID" ShowHeader="true">
                                <HeaderTemplate>
                                    OrgGroup<br />
                                    ID
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblOrgGroupID" runat="server" Text='<%# Bind("OrgGroupID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtOrgGroupID" runat="server" Text='<%# Eval("OrgGroupID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="75px" ID="ftrOrgGroupID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="BuyerID" ShowHeader="true">
                                <ItemTemplate>
                                    <asp:Label ID="lblBuyerID" runat="server" Text='<%# Bind("BuyerID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtBuyerID" runat="server" Text='<%# Eval("BuyerID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="75px" ID="ftrBuyerID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="SupplierID" ShowHeader="true">
                                <HeaderTemplate>
                                    Supplier<br />
                                    ID
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblSupplierID" runat="server" Text='<%# Bind("SupplierID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtSupplierID" runat="server" Text='<%# Eval("SupplierID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="75px" ID="ftrSupplierID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="CarrierID" ShowHeader="true">
                                <HeaderTemplate>
                                    Carrier<br />
                                    ID
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblCarrierID" runat="server" Text='<%# Bind("CarrierID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCarrierID" runat="server" Text='<%# Eval("CarrierID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="75px" ID="ftrCarrierID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="TerminalID" ShowHeader="true">
                                <HeaderTemplate>
                                    Terminal<br />
                                    ID
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblTerminalID" runat="server" Text='<%# Bind("TruckTermID")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtTerminalID" runat="server" Text='<%# Eval("TruckTermID") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="75px" ID="ftrTerminalID" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="CustomerName" ShowHeader="true">
                                <HeaderTemplate>
                                    Customer<br />
                                    Name
                                </HeaderTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="lblCustomerName" runat="server" Text='<%# Bind("CustomerName")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCustomerName" runat="server" Text='<%# Eval("CustomerName") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="100px" ID="ftrCustomerName" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="Tolerance %" ShowHeader="true">
                                <ItemTemplate>
                                    <asp:Label ID="lblTolerancePercentage" runat="server" Text='<%# Bind("Tolerance")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtTolerancePercentage" runat="server" Text='<%# Eval("Tolerance") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="50px" ID="ftrTolerancePercentage" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderStyle-HorizontalAlign="Center" FooterStyle-HorizontalAlign="Center"
                                ItemStyle-HorizontalAlign="Center" HeaderText="Credit/Rebill BOL" ShowHeader="true">
                                <ItemTemplate>
                                    <asp:Label ID="lblCreditRebillBOL" runat="server" Text='<%# Bind("CreditRebillBOL")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:TextBox ID="txtCreditRebillBOL" runat="server" Text='<%# Eval("CreditRebillBOL") %>'></asp:TextBox>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:TextBox Width="20px" ID="ftrCreditRebillBOL" runat="server"></asp:TextBox>
                                </FooterTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField ShowHeader="False">
                                <ItemTemplate>
                                    <asp:LinkButton ID="lnkbtnXRefEdit" runat="server" CausesValidation="false" CommandName="Edit"
                                        Text="Edit"></asp:LinkButton>
                                    <asp:LinkButton ID="lnkbtnXRefDelete" runat="server" CommandName="Delete" Text="Delete"
                                        OnClientClick="return confirm('Are you sure you want to DELETE this entry?');"></asp:LinkButton>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:LinkButton ID="lnkbtnXRefUpdate" runat="server" CausesValidation="true" CommandName="Update"
                                        ValidationGroup="Update" OnClientClick="return confirm('Are you sure you want to UPDATE this entry?');"
                                        Text="Update"></asp:LinkButton>
                                    <asp:LinkButton ID="lnkbtnXRefCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                        Text="Cancel"></asp:LinkButton>
                                </EditItemTemplate>
                                <FooterTemplate>
                                    <asp:LinkButton ID="lnkbtnXRefAddNew" runat="server" CommandName="AddNew" Text="Add New"
                                        CausesValidation="true" ValidationGroup="AddNew"></asp:LinkButton>
                                </FooterTemplate>
                            </asp:TemplateField>
                        </Columns>
                    </asp:GridView>
                </td>
            </tr>
        </table>
    </div>
于 2013-02-05T16:18:42.657 回答