请看图asp.net控件textbox放在td中没法input填充td满

欢迎访问阿里西西WEB开发技术网站!
作者:[转载]&&文章来源:/&&更新时间:
翻译: t.t (tpoi)
在这编文章中, 我将告诉你如何使用.net framework类库中的web类来为web服务器控件创建和应用样式(style).
system.web.ui.webcontrols.style 类
style类定义在system.web.ui.webcontrols名字空间, 用来描叙一个web服务器控件的样式. 该类的属性可以设置web服务器控件的外观, 或者多个web服务器控件使用一个通用的外观. 你可以通过这些属性来改变背景色, 前景色, 边框宽度, 边框样式和web服务器控件大小. 表1为style类的属性
表1. style类的属性
获取或设置 web 服务器控件的背景色
bordercolor
获取或设置 web 服务器控件的边框颜色
borderstyle
获取或设置 web 服务器控件的边框样式
borderwidth
获取或设置 web 服务器控件的边框宽度
获取或设置由 web 服务器控件在客户端呈现的 css 类 font 获取与 web 服务器控件关联的字体属性
获取或设置 web 服务器控件的前景色(通常是文本颜色)
获取或设置 web 服务器控件的高度
获取或设置 web 服务器控件的宽度
system.web.ui.webcontrols.webcontrol.applystyle 方法
applystyle方法是把你之前所设置的样式应用到一个web服务器控件中去. 下面有一小段代码:
// 设置style的属性
………
// 应用style
ctrl.applystyle(s);
现在我将用一个例子来讲解如何在web服务器控件中应用样式. 在visual studio.net中建立一个web应用程序, 在form中添加3个控件, button, textbox, listbox. 给listbox中添加一些items(使用collection属性). 请看图一
现在再创建2个新的方法, createstyle和setcontrolstyle. createstyle方法有7个参数, 为背景色,前景色等传递值. 这个方法返回一个style的对象
// 这个方法创建一个新的样式
createstyle(color backclr, color foreclr, int borderwidth, string fntname, int fntsize, bool fntbold, bool fntitalic)
style s = new style();
s.backcolor =
s.forecolor =
s.borderwidth =
s.font.name =
s.font.size =
s.font.bold =
s.font.italic =
// 这个方法将样式应用到一个web服务器控件中
private void setcontrolstyle(system.web.ui.webcontrols.webcontrol ctrl, style s)
ctrl.applystyle(s);
现在将创建按钮的click event
private void button1_click(object sender, system.eventargs e)
style st = createstyle(color.green, color.yellow, 3, "verdana", 10, true, true);
setcontrolstyle(textbox1, st);
st = createstyle(color.red, color.black, 2, "verdana", 12, true, true);
setcontrolstyle(setstylebtn, st);
st = createstyle(color.blue, color.yellow, 2, "verdana", 12, true, true);
setcontrolstyle(listbox1, st);
现在运行程序Recommended Reading
All good programmers borrow at least part of their code.
So feel free to borrow some of mine.
First off, sorry for the absence.
Things got a little busy in life as well as work.
Not to mention having to get up to speed on 2.0 in a big hurry.
All good things, but it left less time for fun stuff.
With that said, I want to offer a little tip to help with formatting your ASP.Net pages.
Getting a label to be multiline within a set width.
Now many of you know this trick, but I always have to re-remember the trick every time I need it, so this post can be a reference for you as well.
The trick is actually this - Don't use a label.
Use a textbox instead.
Since all the controls inherit from the same base class, the text box and the label are very similar anyway.
But only the textbox has the multiline capability.
Once you have the textbox on your page the trick is to make it look like a label for the end user.
To do this you need to set the following properties (This is the part I can never remember):
Wrap = (obviously)
rows = {some number greater than 0} (I use the rows property rather than the height property as it tends to be earier to get the formatting right)
ReadOnly = true (makes sense, right)
TextMode = multiline (or there no real reason to wrap the text...)
BorderStyle = None
BorderWidth = 0
Those last two are actually VERY important, and here is why.
They get rid of that pesky border that you see around text boxes.
That border is a common visual signal to the end user that says "ENTER INFO HERE!".
If you leave the border up expect a lot of phone calls from folks saying "The web page is broken.
It won't let me enter text."
So use this in good faith.
More controls soon.
Even my first 2.0 controls.
Email: (never displayed)
&(will show your )
Comment: Allowed tags: blockquote, a, strong, em, p, u, strike, super, sub, code
Verification:在ASP.NET WEB控件中应用样式(Style)-打印版本-阿里西西WEB开发社区
标题:在ASP.NET WEB控件中应用样式(Style)
翻译: T.T (TPoI) 在这编文章中, 我将告诉你如何使用.NET FRAMEWORK类库中的WEB类来为WEB服务器控件创建和应用样式(Style).
System.Web.UI.WebControls.Style 类 Style类定义在System.Web.UI.WebControls名字空间, 用来描叙一个WEB服务器控件的样式. 该类的属性可以设置WEB服务器控件的外观, 或者多个WEB服务器控件使用一个通用的外观. 你可以通过这些属性来改变背景色, 前景色, 边框宽度, 边框样式和WEB服务器控件大小. 表1为Style类的属性 表1. Style类的属性 BackColor 获取或设置 Web 服务器控件的背景色 BorderColor 获取或设置 Web 服务器控件的边框颜色 BorderStyle
获取或设置 Web 服务器控件的边框样式
BorderWidth
获取或设置 Web 服务器控件的边框宽度
CssClass 获取或设置由 Web 服务器控件在客户端呈现的 CSS 类 Font 获取与 Web 服务器控件关联的字体属性 ForeColor 获取或设置 Web 服务器控件的前景色(通常是文本颜色) Height 获取或设置 Web 服务器控件的高度
Width 获取或设置 Web 服务器控件的宽度
System.Web.UI.WebControls.WebControl.ApplyStyle 方法 ApplyStyle方法是把你之前所设置的样式应用到一个Web服务器控件中去. 下面有一小段代码: WebC S // 设置Style的属性 ……… // 应用Style ctrl.ApplyStyle(s); 例子 现在我将用一个例子来讲解如何在WEB服务器控件中应用样式. 在Visual Studio.NET中建立一个WEB应用程序, 在Form中添加3个控件, Button, TextBox, ListBox. 给ListBox中添加一些items(使用Collection属性). 请看图一 现在再创建2个新的方法, CreateStyle和SetControlStyle. CreateStyle方法有7个参数, 为背景色,前景色等传递值. 这个方法返回一个Style的对象 // 这个方法创建一个新的样式 CreateStyle(Color backClr, Color foreClr, int borderWidth, string fntName, int fntSize, bool fntBold, bool fntItalic){ Style s = new Style(); s.BackColor = backC s.ForeColor = foreC s.BorderWidth = borderW s.Font.Name = fntN s.Font.Size = fntS s.Font.Bold = fntB s.Font.Italic = fntI
} // 这个方法将样式应用到一个WEB服务器控件中 private void SetControlStyle(System.Web.UI.WebControls.WebControl ctrl, Style s) { ctrl.ApplyStyle(s); } 现在将创建按钮的click event private void Button1_Click(object sender, System.EventArgs e) { Style st = CreateStyle(Color.Green, Color.Yellow, 3, &Verdana&, 10, true, true); SetControlStyle(TextBox1, st); st = CreateStyle(Color.Red, Color.Black, 2, &Verdana&, 12, true, true); SetControlStyle(SetStyleBtn, st); st = CreateStyle(Color.Blue, Color.Yellow, 2, &Verdana&, 12, true, true); SetControlStyle(ListBox1, st); }
Copyright& All Rights Reserved
打印版本 | &阿里西西.&Timer控件,通过txtbox赋值无效的问题.-.NET技术/C#-c/c++-电脑编程网Timer控件,通过txtbox赋值无效的问题.-.NET技术/C#作者:geminizane 和相关&&细节问题请看图,如图所示,我是想通过txtbox1获取输入的链接,点击button1跳转到web,同时,通过txtbox2获取timer的自动刷新的时间.但是,我直接在timer控件的属性里边设置,就可以,当然,不敢设置太少,不然因为没有输入url而程序异常.....这个还不会弄.但是现在我这样写,我觉得好像没错,参照MSDN上的例子,貌似也是这样的,但是为什么我运行之后,输入了时间,页面不自动刷新呢?谢谢.我是新手,有些问题可能有些可笑,但是难得想要认真学习一回...给我点帮助吧,像上图的system.uri都是自己找的,但是timer控件的问题木有找到.谢谢.------回答---------------其他回答(2分)---------断点调试,看txttime的值,我怀疑是空的------其他回答(5分)---------txtBox2的 Change事件中加个判断。C# code
txB2_TextChanged()
{
string str= _txtBox2.T
if(!string.IsNullOrEmpty(str))
int interval = int.Parse(str);
if(interval & 100)
//加个条件,不然程序输入1的时候直接卡死
this.timer1.Interval =
this.timer1.Start();
this.timer1.Stop();
------其他回答(3分)---------C# code
没有问题啊
if (string.IsNullOrEmpty(txttime))
------其他回答(2分)---------timer1里进行了什么操作?------其他回答(2分)---------代码贴全看下。------其他回答(6分)---------Timer1.Click事件中C# code
Timer1_Click(sender,e)
{
//Url转向函数
//你的应该是Button1_Click(),控件的名称最好改下,时间长了都不知道是什么了
button_Click(this.Button1,new EventArg());
}
------其他回答(2分)---------Timer还有Click啊------其他回答(2分)---------timer1.Start()------其他回答(2分)---------C# code
private void timer1_Tick(object sender, EventArgs e)
{
button1.PerformClick();
}
------其他回答(14分)---------C# code
private void timer1_Tick(object sender, EventArgs e)
Text = DateTime.Now.ToString();
private void textBox1_TextChanged(object sender, EventArgs e)
if (string.IsNullOrEmpty(txttime))
int iTime = Convert.ToInt32(textBox1.Text);
if (iTime & 0)
timer1.Enabled =
timer1.Interval = iT
timer1.Enabled =
相关资料:|||||||Timer控件,通过txtbox赋值无效的问题.-.NET技术/C#来源网络,如有侵权请告知,即处理!编程Tags:                &                    自强不息,厚德载物!身心自在,道法自然!
DataList控件
&DataList控件也是一个常用的数据绑定控件,相对于GridView控件虽然没它那么强大的功能,但是灵活性却很强势。因为其本身就是一个富有弹性的控件。DataList控件可以使用模版与定义样式来显示数据,并可以经行数据选择,删除以及编辑。DataList支持的模版有一下介绍:
AlternatingItemTemplate:如果已经定义,DataList中的交替项提供内容和布局;如果未定义则使用ItemTemplate
EditItemTemplate:如果已定义,DataList中的当前编辑项提供内容和布局;如果未定义则使用ItemTemplate
FoterTemplate:如果已定义,DataList中的当前脚注部分提供内容和布局;如果未定义将不显示脚注部分
HeaderTemplate:如果已定义,DataList中的当前页眉部分提供内容和布局;如果未定义将不显示页眉
ItemTemplate:DataList中提供内容和布局所要求的模版
SelectedItemTemplate:如果定义则为DataList当前选项提供内容和布局;如果未定义则使用ItemTemplate
SeparatorTemplate:如果定义则为DataList各项之间的分隔符提供内容和布局,如果未定义,将不显示分隔符
下面实验一个用SQL语句从数据库中查询数据的功能。
先创建一个ASP.NET的网站,然后在页面中添加一个DataList控件,用来显示分页数据。
然后编辑我的DataList控件步骤如下:
编辑ItemTemplate选项,具体代码如下:
&asp:DataList ID="DataList1" runat="server"&
&ItemTemplate&
&tr style="border-bottom-style: border-bottom-width: border-bottom-color: #FFFFFF"&
&td rowspan="3" align="center" class="style3"&
&a href='#'&&/a&
&td align="left"&
&td align="left"&
&td align="left"&
空间主人:&a&&/a&&/td&
&td align="left"&
--创建时间:&a&&/a&&/td&
&td align="left" colspan="3"&
个性签名:&a &&/a&&/td&
&/ItemTemplate&
&FooterTemplate&
&div style="text-align: center"&
&table id="Page" border="1" cellpadding="0" cellspacing="0"
style="font-size: 12 width: 68%"&
&asp:Label ID="labCurrentPage" runat="server"&&/asp:Label&/
&asp:Label ID="labPageCount" runat="server"&&/asp:Label&
&asp:LinkButton ID="lnkbtnFirst" runat="server" CommandName="first" Font-Underline="False"
ForeColor="Black"&首页&/asp:LinkButton&
&asp:LinkButton ID="lnkbtnFront" runat="server" CommandName="pre" Font-Underline="False"
ForeColor="Black"&上一页&/asp:LinkButton&
&asp:LinkButton ID="lnkbtnNext" runat="server" CommandName="next" Font-Underline="False"
ForeColor="Black"&下一页&/asp:LinkButton&
&asp:LinkButton ID="lnkbtnLast" runat="server" CommandName="last" Font-Underline="False"
ForeColor="Black"&尾页&/asp:LinkButton&
&& 跳转至:&asp:TextBox ID="txtPage" runat="server" Width="35px" Height="21px"&&/asp:TextBox&
&asp:Button ID="Button1" runat="server" CommandName="search" Text="GO"
Height="19px" /&
&/FooterTemplate&
&/asp:DataList&
先看我们的数据库里的测试数据:
,然后我们需要搞一个数据分页的功能,并且将分页的数据绑定到DataList空间上。
具体代码如:
/// &summary&
/// 实现数据分页
/// &/summary&
/// &param name="currentpage"&&/param&
private void BindDataList(int currentpage)
pds.AllowPaging =
//允许分页
pds.PageSize = 4;
//每页4条数据
pds.CurrentPageIndex = //当前页为传人的一个int类型
string querySql = string.Format("SELECT * FROM dbo.Message");
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(querySql, connection);
DataSet ds = new DataSet();
//执行得到的数据放在数据集中
sda.Fill(ds);
//数据集中的数据放入到分页数据中
pds.DataSource = ds.Tables[0].DefaultV
this.DataList1.DataSource =
this.DataList1.DataBind();
connection.Close();
&然后我们需要触发DataList的ItemDataBound事件来显示控件中当前的页码和总页码。然后设置分页按钮是否可用的状态:
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
switch (e.CommandName)
//以下5个为 捕获用户点击 上一页 下一页等时发生的事件
case "first"://第一页
pds.CurrentPageIndex = 0;
BindDataList(pds.CurrentPageIndex);
case "pre"://上一页
pds.CurrentPageIndex = pds.CurrentPageIndex - 1;
BindDataList(pds.CurrentPageIndex);
case "next"://下一页
pds.CurrentPageIndex = pds.CurrentPageIndex + 1;
BindDataList(pds.CurrentPageIndex);
case "last"://最后一页
pds.CurrentPageIndex = pds.PageCount - 1;
BindDataList(pds.CurrentPageIndex);
case "search"://页面跳转页
if (e.Item.ItemType == ListItemType.Footer)
int PageCount = int.Parse(pds.PageCount.ToString());
TextBox txtPage = e.Item.FindControl("txtPage") as TextB
int MyPageNum = 0;
if (!txtPage.Text.Equals(""))
MyPageNum = Convert.ToInt32(txtPage.Text.ToString());
if (MyPageNum &= 0 || MyPageNum & PageCount)
Response.Write("&script&alert('请输入页数并确定没有超出总页数!')&/script&");
BindDataList(MyPageNum - 1);
&然后我们继续对DataList控件的ItemCommand事件,在该事件中,主要针对&首页/上一页/下一页/末页&分页按钮被点击时,以及在文本框输入页数跳转功能的实现简单操作:
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
if (e.Item.ItemType == ListItemType.Footer)
//以下六个为得到脚模板中的控件,并创建变量.
Label CurrentPage = e.Item.FindControl("labCurrentPage") as L
Label PageCount = e.Item.FindControl("labPageCount") as L
LinkButton FirstPage = e.Item.FindControl("lnkbtnFirst") as LinkB
LinkButton PrePage = e.Item.FindControl("lnkbtnFront") as LinkB
LinkButton NextPage = e.Item.FindControl("lnkbtnNext") as LinkB
LinkButton LastPage = e.Item.FindControl("lnkbtnLast") as LinkB
CurrentPage.Text = (pds.CurrentPageIndex + 1).ToString();//绑定显示当前页
PageCount.Text = pds.PageCount.ToString();//绑定显示总页数
if (pds.IsFirstPage)//如果是第一页,首页和上一页不能用
FirstPage.Enabled =
PrePage.Enabled =
if (pds.IsLastPage)//如果是最后一页"下一页"和"尾页"按钮不能用
NextPage.Enabled =
LastPage.Enabled =
&完全的代码如下:
using System.Collections.G
using System.D
using System.Data.SqlC
using System.L
using System.W
using System.Web.UI;
using System.Web.UI.WebC
namespace DataListApplaction
public partial class DataListDemo : System.Web.UI.Page
static PagedDataSource pds = new PagedDataSource();
//创建一个分页数据源的对象且一定要声明为静态
//连接字符串
SqlConnection connection = new SqlConnection(@"Data Source=.\CENA;Initial Catalog=Asp.Persist Security Info=TUser ID=Password=123456");
protected void Page_Load(object sender, EventArgs e)
if (!IsPostBack)
BindDataList(0);
/// &summary&
/// 实现数据分页
/// &/summary&
/// &param name="currentpage"&&/param&
private void BindDataList(int currentpage)
pds.AllowPaging = true;
//允许分页
pds.PageSize = 4;
//每页4条数据
pds.CurrentPageIndex = //当前页为传人的一个int类型
string querySql = string.Format("SELECT * FROM dbo.Message");
connection.Open();
SqlDataAdapter sda = new SqlDataAdapter(querySql, connection);
DataSet ds = new DataSet();
//执行得到的数据放在数据集中
sda.Fill(ds);
//数据集中的数据放入到分页数据中
pds.DataSource = ds.Tables[0].DefaultV
this.DataList1.DataSource =
this.DataList1.DataBind();
connection.Close();
protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
switch (e.CommandName)
//以下5个为 捕获用户点击 上一页 下一页等时发生的事件
case "first"://第一页
pds.CurrentPageIndex = 0;
BindDataList(pds.CurrentPageIndex);
case "pre"://上一页
pds.CurrentPageIndex = pds.CurrentPageIndex - 1;
BindDataList(pds.CurrentPageIndex);
case "next"://下一页
pds.CurrentPageIndex = pds.CurrentPageIndex + 1;
BindDataList(pds.CurrentPageIndex);
case "last"://最后一页
pds.CurrentPageIndex = pds.PageCount - 1;
BindDataList(pds.CurrentPageIndex);
case "search"://页面跳转页
if (e.Item.ItemType == ListItemType.Footer)
int PageCount = int.Parse(pds.PageCount.ToString());
TextBox txtPage = e.Item.FindControl("txtPage") as TextB
int MyPageNum = 0;
if (!txtPage.Text.Equals(""))
MyPageNum = Convert.ToInt32(txtPage.Text.ToString());
if (MyPageNum &= 0 || MyPageNum & PageCount)
Response.Write("&script&alert('请输入页数并确定没有超出总页数!')&/script&");
BindDataList(MyPageNum - 1);
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
if (e.Item.ItemType == ListItemType.Footer)
//以下六个为得到脚模板中的控件,并创建变量.
Label CurrentPage = e.Item.FindControl("labCurrentPage") as L
Label PageCount = e.Item.FindControl("labPageCount") as L
LinkButton FirstPage = e.Item.FindControl("lnkbtnFirst") as LinkB
LinkButton PrePage = e.Item.FindControl("lnkbtnFront") as LinkB
LinkButton NextPage = e.Item.FindControl("lnkbtnNext") as LinkB
LinkButton LastPage = e.Item.FindControl("lnkbtnLast") as LinkB
CurrentPage.Text = (pds.CurrentPageIndex + 1).ToString();//绑定显示当前页
PageCount.Text = pds.PageCount.ToString();//绑定显示总页数
if (pds.IsFirstPage)//如果是第一页,首页和上一页不能用
FirstPage.Enabled = false;
PrePage.Enabled = false;
if (pds.IsLastPage)//如果是最后一页"下一页"和"尾页"按钮不能用
NextPage.Enabled = false;
LastPage.Enabled = false;
写完程序运行结果如下:
关于DataList就先了解到这里,下面在列举一下DataList常用的事件
CancelCommand
对DataList控件中的某项单击Cancel按钮时发生
DeleteCommand
对DataList控件中的某项单击Delete按钮时发生
EditCommand
对DataList控件中的某项单击Edit按钮时发生
ItemCommand
当单击DataList控件的任意按钮时发生
ItemDataBound
当项被数据绑定到DataList控件时发生
SelectedIndexChanged
在两次服务发送之间,在数据列表控件中选择了不同的项时发生
UpdateCommand
对DataList控件中的某项单击Update时发生
阅读(...) 评论()
路漫漫其修远兮,吾将上下而求索!

我要回帖

更多关于 td填充颜色 的文章

 

随机推荐