By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,215 Members | 1,935 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,215 IT Pros & Developers. It's quick & easy.

Changing font on Pushbutton control

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.