我有一个asp gridview控件,可以通过数据库填充(允许分页)。我还允许用户编辑一行中的任何单元格。 gridview控件包含在此div标签中 这使它更小,占用更少的屏幕。它完美运行,直到我点击编辑按钮,导致所选行变为编辑模式。当它执行此操作时,将编辑行突出显示为颜色,并在该行文本框上进行控制。我在gridview中为每列使用模板。以下;
模板列 ItemTemplate中 EditTemplate FooterTemplate
每列的。当gridview切换到editmode时,它渲染网格基本上是默认大小调整,它占用了所有屏幕并且看起来很糟糕......似乎忽略了div标签。有关为什么在编辑模式和非编辑模式之间切换渲染大小的任何想法?当我取消编辑操作时,它会在网格的初始加载时呈现回正确的大小:(
答案 0 :(得分:1)
可能是编辑模式文本框使你的网格失控。您的DIV字体大小仅适用于文本范围元素,而不适用于文本框。
尝试设置文本框的样式以减小其大小。每个链接here:
<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}
答案 1 :(得分: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>
答案 2 :(得分:0)
使用:
< Control style width="" /> between < asp:Boundfield>----< /asp:Boundfield>
它将立即解决。