473,732 Members | 2,083 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.ItemT ype.Item ||
e.Item.ItemType .AlternatingIte m)
{
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 1868
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.dt d">

<script runat="server">

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

Protected Sub dg1_ItemCreated (ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs)
Dim btn As Button
If e.Item.ItemType <> ListItemType.He ader Or e.Item.ItemType <>
ListItemType.Fo oter Then
btn = e.Item.FindCont rol("pushbutton 1")
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 CreateDataSourc e() 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 _
("StringValu e", 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>Untitl ed Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:datagrid id="dg1" runat="server" onitemcreated=" dg1_ItemCreated ">
<columns>
<asp:templateco lumn headertext="Str ingValue">
<itemtemplate >
<asp:button id="pushbutton1 " runat="server"
causesvalidatio n="false" commandname="" text='<%# DataBinder.Eval (Container,
"DataItem.Strin gValue") %>' />
</itemtemplate>
</asp:templatecol umn>
</columns>
</asp:datagrid>
</div>
</form>
</body>
</html>
"Blasting Cap" <go****@christi an.net> wrote in message
news:uD******** *****@TK2MSFTNG P05.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.ItemT ype.Item ||
e.Item.ItemType .AlternatingIte m)
{
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
6646
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 RTB control. Whenever I change the font type during the runtime by selecting a font name from a combobox -of all system fonts, the text changes its font correctly but I loose some formatting such as a bold text and/or titles become normal text.
1
32233
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: Property or indexer "System.Drawing.Font.Size' cannot be assigned to -- it is read only I can change a button's text property during runtime, but I'd also like to change the font size as well.
7
8989
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 then change the label in front of the textbox or dropdown list to red... is this possible with asp.net? It seems you can only put a RequiredFieldValidator on the page, and if it fails validation then that text is displayed... ? Thanks
11
1817
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 standard grey but, if I apply this to an HtmlInput control, all that does is change the background and foreground colours in the textbox portion. Similarly, if I modify the style attribute, that only applies to the textbox portion too.
6
10499
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 done without API calls? Thanks Ioannis
3
1851
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() rtbData.SelectionFont = New Font(f, f.Style + (IIf(f.Bold, FontStyle.Bold * -1, FontStyle.Bold)))
7
2971
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 already formatted as "Shopping" ---Bold "for" -----Regular Now I want to underline whole text by preserving old style i.e. Bold and
0
1194
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 CreateChildControls again . There's a datagrid in the user control . The datagrid bind the data when the user control be loaded at the first
0
1138
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) { treeview1.FontBold = true; treeview1.Font.Name = "DVB-TTSurekh"; treeview1.FontSize = Font.FontUnit(14);
0
9445
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9306
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6733
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2177
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.