473,499 Members | 1,689 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Changing font on Pushbutton control

I am having trouble changing the font for a PushButton control in a
datagrid button column. I have seen several posts refer to styles and
simple changes to the HTML for font changes but most of those referred
to a LinkButton type of control. But in cases where someone is using the
PushButton there are no posted solutions. Whenever these changes are
made to the PushButton control they do not make any requested changes.

I have seen one board that posted the following code in C# that stated
it would fix the problem.

if(e.Item.ItemType.Item ||
e.Item.ItemType.AlternatingItem)
{
Button btn = (Button)e.Item.Cells[X].Controls[0];
btn.Font.Name = "verdana";
FontUnit.Point(8);
}

I am not sure if this type of code would go before the databind call or
after or what...

Any suggestions on how to do this with VB.Net code?

Any help or advice would be greatly appreciated.

BC

Jun 23 '06 #1
1 1853
Hi Blasting (using a real name is considered more polite)

Here's some code that should get you going. You need to get a reference to
the button and then change the button's characteristics much the way you saw
in the C# code.

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
If Not IsPostBack Then
dg1.DataSource = CreateDataSource()
dg1.DataBind()
End If
End Sub

Protected Sub dg1_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs)
Dim btn As Button
If e.Item.ItemType <> ListItemType.Header Or e.Item.ItemType <>
ListItemType.Footer Then
btn = e.Item.FindControl("pushbutton1")
If Not IsNothing(btn) Then
btn.Font.Italic = True
btn.Font.Name = "verdana"
btn.Font.Size = FontUnit.Point(8)
End If
End If
End Sub

Function CreateDataSource() As Data.DataTable
Dim dt As New Data.DataTable
Dim dr As Data.DataRow
dt.Columns.Add(New Data.DataColumn _
("IntegerValue", GetType(Int32)))
dt.Columns.Add(New Data.DataColumn _
("StringValue", GetType(String)))
dt.Columns.Add(New Data.DataColumn _
("CurrencyValue", GetType(Double)))
dt.Columns.Add(New Data.DataColumn _
("Boolean", GetType(Boolean)))
Dim i As Integer
For i = 0 To 5
dr = dt.NewRow()
dr(0) = i
dr(1) = "Item " + i.ToString()
dr(2) = 1.23 * (i + 1)
dr(3) = (i = 4)
dt.Rows.Add(dr)
Next i
Return dt
End Function
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg1" runat="server" onitemcreated="dg1_ItemCreated">
<columns>
<asp:templatecolumn headertext="StringValue">
<itemtemplate>
<asp:button id="pushbutton1" runat="server"
causesvalidation="false" commandname="" text='<%# DataBinder.Eval(Container,
"DataItem.StringValue") %>' />
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>
"Blasting Cap" <go****@christian.net> wrote in message
news:uD*************@TK2MSFTNGP05.phx.gbl...
I am having trouble changing the font for a PushButton control in a
datagrid button column. I have seen several posts refer to styles and
simple changes to the HTML for font changes but most of those referred to a
LinkButton type of control. But in cases where someone is using the
PushButton there are no posted solutions. Whenever these changes are made
to the PushButton control they do not make any requested changes.

I have seen one board that posted the following code in C# that stated it
would fix the problem.

if(e.Item.ItemType.Item ||
e.Item.ItemType.AlternatingItem)
{
Button btn = (Button)e.Item.Cells[X].Controls[0];
btn.Font.Name = "verdana";
FontUnit.Point(8);
}

I am not sure if this type of code would go before the databind call or
after or what...

Any suggestions on how to do this with VB.Net code?

Any help or advice would be greatly appreciated.

BC

Jun 23 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6626
by: Cengiz Ulku | last post by:
Hi all, I know now how to change the font name of a RTF file in a RTB control using, for example: RTextBox1.SelFontName = cmbFonts.Text I have a RTF file -created with Word- displayed in a...
1
32217
by: Jeff N | last post by:
It it possible to change a button's or text box's font size during runtime? When I try to build my application with this code: this.ActiveControl.Font.Size = "8.25"; I get this error message:...
7
8918
by: Ed West | last post by:
Hello, I have a simple form with some input boxes. After validation if one fails, then I would like to at the top of the page say something like "The following fields in red are required" and...
11
1794
by: Mark Rae | last post by:
Hi, Is there any way to modify the style of the button portion of an HtmlInput control? I have a CSS class which I use for all of the buttons to try to make them a little less ugly than the...
6
10458
by: Ioannis Demetriades | last post by:
Hi, I need to change the printer's font to "control" -a printer font, and then send a sequence of characters to the printer. My problem is that I cannot change the printer's font. Can this be...
3
1835
by: Sakharam Phapale | last post by:
Hi All, I am using a richTextBox control for text editing purpose. I have written following procedure which change the font style of richTextBox. Dim f as font = rtbData.selectionFont() ...
7
2925
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
0
1185
by: DotQuery | last post by:
Hello ASP.NET team : I have a user control that be added into page at runtime , in a postback event handler . I save the information to view state , and load the user control again in...
0
1125
by: Santosh | last post by:
Dear all i am downloading MS tree view control . i want to change the font size and font name of the tree view control i am wrtitting code for it like if (!Page.IsPostBack) {...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7229
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.