GridView.EmptyDataRowStyle Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Получает ссылку на TableItemStyle объект, позволяющий задать внешний вид пустой строки данных, отображаемой при GridView привязке элемента управления к источнику данных, который не содержит записей.
public:
property System::Web::UI::WebControls::TableItemStyle ^ EmptyDataRowStyle { System::Web::UI::WebControls::TableItemStyle ^ get(); };
[System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)]
public System.Web.UI.WebControls.TableItemStyle EmptyDataRowStyle { get; }
[<System.Web.UI.PersistenceMode(System.Web.UI.PersistenceMode.InnerProperty)>]
member this.EmptyDataRowStyle : System.Web.UI.WebControls.TableItemStyle
Public ReadOnly Property EmptyDataRowStyle As TableItemStyle
Значение свойства
Ссылка на ту TableItemStyle , которая позволяет задать внешний вид строки NULL.
- Атрибуты
Примеры
В следующем примере показано, как задать EmptyDataRowStyle свойство декларативно, чтобы указать светло-синий фон и красный шрифт для строки NULL.
<%@ Page language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView EmptyDataTemplate Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
runat="server">
<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>
<emptydatatemplate>
<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>
No Data Found.
</emptydatatemplate>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. The following query -->
<!-- returns an empty data source to demonstrate the -->
<!-- empty row. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GridView EmptyDataTemplate Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>GridView EmptyDataTemplate Example</h3>
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="true"
runat="server">
<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>
<emptydatatemplate>
<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>
No Data Found.
</emptydatatemplate>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. Use an ASP.NET -->
<!-- expression to retrieve the connection string value -->
<!-- from the Web.config file. The following query -->
<!-- returns an empty data source to demonstrate the -->
<!-- empty row. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers] Where CustomerID='NoID'"
connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
Комментарии
EmptyDataRowStyle Используйте свойство для управления внешним видом строки NULL в элементе GridView управления. Строка NULL отображается, когда источник данных, привязанный к элементу управления, не содержит записей. Это свойство доступно только для чтения; однако можно задать свойства возвращаемого TableItemStyle объекта. Свойства можно задать декларативно с помощью одного из следующих методов:
Поместите атрибут в открывающий тег GridView элемента управления в форме
Property-Subproperty, гдеSubpropertyявляется свойством TableItemStyle объекта (например,EmptyDataRowStyle-ForeColor).Вложен элемент
<EmptyDataRowStyle>между открывающим и закрывающим тегами GridView элемента управления.
Свойства также можно задать программным способом в форме Property.Subproperty (например, EmptyDataRowStyle.ForeColor). Общие параметры обычно включают настраиваемый цвет фона, цвет переднего плана и свойства шрифта.