Itz.Irshad
Itz.Irshad

Reputation: 1024

How to set font-size of text box in bounded fields of grid view template fields?

In ASP.NET 2.0 web application, there is a gridview and user wanted to change the font size of contents of that grid view. Below is Gridview definition and server side code to set the font-size of contents of gridview. Everything is fine except, textboxes in bounded fields of gridview. The font size does not applied on them.

GridView :

<asp:TemplateField HeaderText="Display Name" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left">
        <ItemTemplate>
            <asp:TextBox ID="TextBox1" runat="server" Width="100px" Text='<%# Bind("DisplayName") %>' OnTextChanged="TextBox_TextChanged" />
            <asp:HiddenField ID="HiddenField1" runat="server" Value='<%# Eval("DisplayName") %>' />
        </ItemTemplate>
</asp:TemplateField>

ServerSide Code:

 ObjPListSetting.Style["font-size"] = sTextSize + "px";

where, sTextSize is target value (i.e. 12, 14, 16).

Why is that so? Anyone can help in this regard.

Upvotes: 0

Views: 2358

Answers (1)

Narendra
Narendra

Reputation: 3117

In the OnRowDataBound event hander do something like this.

TextBox txtTextBox1 = RowObject.FindControl("TextBox1");
txtTextBox1.Style["font-size"] = sTextSize + "px";

This is a dummy code. Just check how you get the rowobject in below link. http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound.aspx

Upvotes: 1

Related Questions