Answered by:
keep gridview font size the same in both select and edit modes

Question
-
User154499744 posted
I have a gridview with Edit enabled. I have the Font-Size set to "Small". When the gridview renders the data, the data is shown in Small font. But when I hit the Edit button and it goes into Edit mode, the font size changes and the gridview also changes in size to fit the new font size.
What is the best way to keep the font size (and thus the gridview size) the same both in Select and Edit modes?
Monday, May 23, 2016 3:35 PM
Answers
-
User1559292362 posted
Hi NewKid1nTown,
NewKid1nTown
What is the best way to keep the font size (and thus the gridview size) the same both in Select and Edit modes?It seems that you need to style your textbox. and I create a demo as below for your reference.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewWithEditItemplate.aspx.cs" Inherits="ADONETDEMO.GridViewDemo.GridViewWithEditItemplate" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style> .yourclass { color:red; font-size:smaller; } .yourclass2 { color:red; font-size:large; } .inputstyle{ color:#ff0000; font-size:smaller; } .inputstyle2{ color:#ff0000; font-size:large; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" onrowcancelingedit="GridView1_RowCancelingEdit" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" onrowdatabound="GridView1_RowDataBound"> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate > <asp:Label ID="Label6" runat="server" Text='<%# Eval("Id") %>' ></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate > <asp:Label runat="server" Text='<%# Eval("Name") %>' CssClass ="yourclass"></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name")%>' CssClass="inputstyle"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("Price") %>'></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("Price") %>' ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Category"> <ItemTemplate > <asp:Label ID="Label3" runat="server" Text='<%# Eval("Category") %>' CssClass ="yourclass2"></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("Category") %>' CssClass ="yourclass2"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ImageId"> <ItemTemplate > <asp:Label ID="Label5" runat="server" Text='<%# Eval("ImageId") %>'></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox5" runat="server" Text='<%# Eval("ImageId") %>' ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Edit" ShowHeader="false"> <ItemTemplate> <asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" ></asp:LinkButton> </ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" ></asp:LinkButton> <asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </EditItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#CCCCCC" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> </div> </form> </body> </html>
Best regards,
Cole Wu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 24, 2016 5:26 AM
All replies
-
User1559292362 posted
Hi NewKid1nTown,
NewKid1nTown
What is the best way to keep the font size (and thus the gridview size) the same both in Select and Edit modes?It seems that you need to style your textbox. and I create a demo as below for your reference.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridViewWithEditItemplate.aspx.cs" Inherits="ADONETDEMO.GridViewDemo.GridViewWithEditItemplate" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <style> .yourclass { color:red; font-size:smaller; } .yourclass2 { color:red; font-size:large; } .inputstyle{ color:#ff0000; font-size:smaller; } .inputstyle2{ color:#ff0000; font-size:large; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None" onrowcancelingedit="GridView1_RowCancelingEdit" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" onrowdatabound="GridView1_RowDataBound"> <RowStyle BackColor="#F7F6F3" ForeColor="#333333" /> <Columns> <asp:TemplateField HeaderText="ID"> <ItemTemplate > <asp:Label ID="Label6" runat="server" Text='<%# Eval("Id") %>' ></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Name"> <ItemTemplate > <asp:Label runat="server" Text='<%# Eval("Name") %>' CssClass ="yourclass"></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Name")%>' CssClass="inputstyle"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Price"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Eval("Price") %>'></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("Price") %>' ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Category"> <ItemTemplate > <asp:Label ID="Label3" runat="server" Text='<%# Eval("Category") %>' CssClass ="yourclass2"></asp:Label> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Eval("Category") %>' CssClass ="yourclass2"></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="ImageId"> <ItemTemplate > <asp:Label ID="Label5" runat="server" Text='<%# Eval("ImageId") %>'></asp:Label> </ItemTemplate> <EditItemTemplate > <asp:TextBox ID="TextBox5" runat="server" Text='<%# Eval("ImageId") %>' ></asp:TextBox> </EditItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Edit" ShowHeader="false"> <ItemTemplate> <asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" ></asp:LinkButton> </ItemTemplate> <EditItemTemplate> <asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" ></asp:LinkButton> <asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel"></asp:LinkButton> </EditItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" /> <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" /> <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" /> <EditRowStyle BackColor="#CCCCCC" /> <AlternatingRowStyle BackColor="White" ForeColor="#284775" /> </asp:GridView> </div> </form> </body> </html>
Best regards,
Cole Wu
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Tuesday, May 24, 2016 5:26 AM -
User154499744 posted
Thank you. I am new to much of this. I will follow your example and see.
Tuesday, May 24, 2016 6:29 PM