473,692 Members | 1,891 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 1863
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
6645
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
32230
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
8970
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
1813
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
10489
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
1847
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
2965
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
1192
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
1134
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
8603
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
9083
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...
1
8797
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
8800
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
5818
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4323
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4557
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2972
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
1957
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.