CssStyleCollection.Count プロパティ
CssStyleCollection オブジェクト内の項目の数を取得します。
名前空間: System.Web.UI
アセンブリ: System.Web (system.web.dll 内)
構文
'宣言
Public ReadOnly Property Count As Integer
'使用
Dim instance As CssStyleCollection
Dim value As Integer
value = instance.Count
public int Count { get; }
public:
property int Count {
int get ();
}
/** @property */
public int get_Count ()
public function get Count () : int
適用できません。
プロパティ値
CssStyleCollection オブジェクト内の項目の数。
使用例
HtmlInputText サーバー コントロールの Count プロパティの現在の値を取得する CountStyleFunc
関数を作成して、その値を ASP.NET ページに表示する例を次に示します。
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<!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 EventArgs)
If Not IsPostBack Then
CountStyleFunc(sender, e)
End If
End Sub
Protected Sub CountStyleFunc(ByVal sender As Object, ByVal e As EventArgs)
Dim styleCount As Integer
' Get the StylesCollection Count.
styleCount = mytextBox.Style.Count
Response.Write("<br /> CssStyleCollection Count " & styleCount)
End Sub
Protected Sub AddBtn_Click(ByVal Src As Object, ByVal e As EventArgs)
' Add style to textbox.
mytextBox.Style("background-color") = "green"
CountStyleFunc(Src, e)
End Sub
Protected Sub ClearButton_Click(ByVal Src As Object, ByVal e As EventArgs)
mytextBox.Style.Clear()
CountStyleFunc(Src, e)
End Sub
Protected Sub RemoveButton_Click(ByVal Src As Object, ByVal e As EventArgs)
mytextBox.Style.Remove("background-color")
CountStyleFunc(Src, e)
End Sub
Protected Sub ShowButton_Click(ByVal Src As Object, ByVal e As EventArgs)
Dim dt As New DataTable()
Dim dr As DataRow
dt.Columns.Add(New DataColumn("AttributeName", GetType(String)))
dt.Columns.Add(New DataColumn("AttributeValue", GetType(String)))
' Get the styles collection.
Dim styleKey As Object
For Each styleKey In mytextBox.Style.Keys
dr = dt.NewRow()
dr(0) = CStr(styleKey)
dr(1) = mytextBox.Style(CStr(styleKey))
dt.Rows.Add(dr)
Next styleKey
Dim dv As New DataView(dt)
DataList1.DataSource = dv
DataList1.DataBind()
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CssStyleCollection Example</title>
</head>
<body>
<form id="CSSForm" runat="server">
<div>
<input type="text"
id="mytextBox"
style="color:black;font: 12pt arial;"
runat="server"
name="mytextBox"/>
<br /> <br />
<input type="Button"
id="addBtn"
value="AddStyle"
onserverclick="AddBtn_Click"
runat="server"
name="addBtn"/>
<input type="Button"
id="removeBtn"
value="RemoveStyle"
onserverclick="RemoveButton_Click"
runat="server"
name="removeBtn"/>
<input type="Button"
id="clearBtn"
value="ClearStyle"
onserverclick="ClearButton_Click"
runat="server"
name="clearBtn"/>
<input type="Button"
id="showBtn"
value="ShowAllStyles"
onserverclick="ShowButton_Click"
runat="server"
name="showBtn"/>
<asp:DataList id="DataList1"
runat="server">
<HeaderStyle Font-Bold="true"/>
<HeaderTemplate>
CssStyleCollection
</HeaderTemplate>
<ItemTemplate>
Attribute:
<%# DataBinder.Eval(Container.DataItem, "AttributeName") %>
,
Value:
<%# DataBinder.Eval(Container.DataItem, "AttributeValue") %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
<%@ Page Language="C#" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
CountStyleFunc(sender, e);
}
protected void CountStyleFunc(object sender, EventArgs e)
{
int styleCount;
// Get the StylesCollection Count.
styleCount = mytextBox.Style.Count;
Response.Write("<br /> CssStyleCollection Count " + styleCount);
}
protected void AddBtn_Click(Object Src, EventArgs e)
{
// Add style to textbox.
mytextBox.Style["background-color"] = "green";
CountStyleFunc(Src, e);
}
protected void ClearButton_Click(Object Src, EventArgs e)
{
mytextBox.Style.Clear();
CountStyleFunc(Src, e);
}
protected void RemoveButton_Click(Object Src, EventArgs e)
{
mytextBox.Style.Remove("background-color");
CountStyleFunc(Src, e);
}
protected void ShowButton_Click(Object Src, EventArgs e)
{
DataTable dt = new DataTable();
DataRow dr;
dt.Columns.Add(new DataColumn("AttributeName", typeof(String)));
dt.Columns.Add(new DataColumn("AttributeValue", typeof(String)));
// Get the styles collection.
foreach (object styleKey in mytextBox.Style.Keys)
{
dr = dt.NewRow();
dr[0] = (string)styleKey;
dr[1] = mytextBox.Style[(string)styleKey];
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
DataList1.DataSource = dv;
DataList1.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>CssStyleCollection Example</title>
</head>
<body>
<form id="CSSForm" runat="server">
<div>
<input type="text"
id="mytextBox"
style="color:black;font: 12pt arial;"
runat="server"
name="mytextBox"/>
<br /> <br />
<input type="Button"
id="addBtn"
value="AddStyle"
onserverclick="AddBtn_Click"
runat="server"
name="addBtn"/>
<input type="Button"
id="removeBtn"
value="RemoveStyle"
onserverclick="RemoveButton_Click"
runat="server"
name="removeBtn"/>
<input type="Button"
id="clearBtn"
value="ClearStyle"
onserverclick="ClearButton_Click"
runat="server"
name="clearBtn"/>
<input type="Button"
id="showBtn"
value="ShowAllStyles"
onserverclick="ShowButton_Click"
runat="server"
name="showBtn"/>
<asp:DataList id="DataList1"
runat="server">
<HeaderStyle Font-Bold="true"/>
<HeaderTemplate>
CssStyleCollection
</HeaderTemplate>
<ItemTemplate>
Attribute:
<%# DataBinder.Eval(Container.DataItem, "AttributeName") %>
,
Value:
<%# DataBinder.Eval(Container.DataItem, "AttributeValue") %>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
プラットフォーム
Windows 98,Windows Server 2000 SP4,Windows CE,Windows Millennium Edition,Windows Mobile for Pocket PC,Windows Mobile for Smartphone,Windows Server 2003,Windows XP Media Center Edition,Windows XP Professional x64 Edition,Windows XP SP2,Windows XP Starter Edition
Microsoft .NET Framework 3.0 は Windows Vista,Microsoft Windows XP SP2,および Windows Server 2003 SP1 でサポートされています。
バージョン情報
.NET Framework
サポート対象 : 3.0,2.0,1.1,1.0
参照
関連項目
CssStyleCollection クラス
CssStyleCollection メンバ
System.Web.UI 名前空間
Style