HyperLinkColumn.FormatDataNavigateUrlValue(Object) 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
DataNavigateUrlFormatString 속성으로 지정한 형식을 사용하여 데이터 바인딩된 URL의 서식을 지정합니다.
protected:
virtual System::String ^ FormatDataNavigateUrlValue(System::Object ^ dataUrlValue);
protected virtual string FormatDataNavigateUrlValue (object dataUrlValue);
abstract member FormatDataNavigateUrlValue : obj -> string
override this.FormatDataNavigateUrlValue : obj -> string
Protected Overridable Function FormatDataNavigateUrlValue (dataUrlValue As Object) As String
매개 변수
- dataUrlValue
- Object
서식을 지정할 데이터 바인딩된 URL입니다.
반환
DataNavigateUrlFormatString 속성으로 지정한 형식으로 된 데이터 바인딩된 URL을 반환합니다.
예제
참고
다음 코드 샘플 단일 파일 코드 모델을 사용 하 고 코드 숨김 파일에 직접 복사 하는 경우 제대로 작동 하지 않을 수 있습니다. 이 코드 샘플.aspx 확장명이 있는 빈 텍스트 파일에 복사 해야 합니다. Web Forms 코드 모델에 대 한 자세한 내용은 참조 하세요. ASP.NET Web Forms 페이지 코드 모델합니다.
<!--
This example demonstrates using a hyperlink column. The code below
should be copied into a file called HyperTextColumnCS.aspx. The file
should be stored in the same directory as the file DetailsPageCS.aspx
described below.
-->
<!--
This example demonstrates using a hyperlink column. The code below
should be copied into a file called HyperTextColumnVB.aspx. The file
should be stored in the same directory as the file DetailsPageVB.aspx
described below.
-->
<%@ Page language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ 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">
private DataView dv;
private DataTable dt = new DataTable();
private void Page_Load(object sender, System.EventArgs e)
{
// Create a DataTable to use as the data source for
// the DataGrid.
dt.Columns.Add(new DataColumn("ItemNumber"));
dt.Columns["ItemNumber"].Caption = "Item Number";
dt.Columns.Add(new DataColumn("Item"));
dt.Columns["ItemNumber"].Caption = "Item";
dt.Columns.Add(new DataColumn("Price"));
dt.Columns["ItemNumber"].Caption = "Price";
// Add some data to the DataTable.
DataRow myDataRow;
for (int i = 0; i < 5; i++)
{
myDataRow = dt.NewRow();
myDataRow[0] = i;
myDataRow[1] = "Item " + i.ToString();
myDataRow[2] = 1.23 * (i + 1);
dt.Rows.Add(myDataRow);
}
// Use the table to create a DataView.
dv = new DataView(dt);
//<Snippet4>
// Create hyperlink columns that contain the item name
// and price.
HyperLinkColumn nameCol = new HyperLinkColumn();
nameCol.DataNavigateUrlField = "ItemNumber";
nameCol.DataTextField = "Item";
nameCol.DataNavigateUrlFormatString =
"DetailspageCS.aspx?id={0}";
nameCol.HeaderText = dt.Columns["Item"].Caption;
HyperLinkColumn priceCol = new HyperLinkColumn();
priceCol.DataNavigateUrlField = "ItemNumber";
priceCol.DataTextField = "Price";
priceCol.DataNavigateUrlFormatString =
"DetailspageCS.aspx?id={0}";
priceCol.DataTextFormatString = "{0:c}";
priceCol.HeaderText = dt.Columns["Price"].Caption;
//</Snippet4>
// Add the new columns to the DataGrid.
DataGrid1.Columns.Add(nameCol);
DataGrid1.Columns.Add(priceCol);
// Set the DataView as the data source, and bind
// it to the DataGrid.
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
ListItemType itemType = (ListItemType)e.Item.ItemType;
if ((itemType != ListItemType.Header) &&
(itemType != ListItemType.Footer) &&
(itemType != ListItemType.Separator))
{
//<Snippet5>
// Get the IntegerValue cell from the grid's column
// collection.
TableCell currentCell = (TableCell)e.Item.Controls[0];
DataGrid1.Columns[1].InitializeCell(currentCell, 1,
ListItemType.Item);
//</Snippet5>
//<Snippet6>
// Add attributes to the cell.
currentCell.Attributes.Add("id", "currentCell" +
e.Item.ItemIndex.ToString());
currentCell.Attributes.Add("OnClick",
"Update_currentCell" +
e.Item.ItemIndex.ToString() +
"()");
//</Snippet6>
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HyperLinkColumn Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid Runat="server" ID="DataGrid1" CellPadding="4"
AutoGenerateColumns="False" BorderStyle="None" GridLines="None">
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Black">
</HeaderStyle>
</asp:DataGrid>
<p>Click on an item name or price to add the item to your order.</p>
</form>
</body>
</html>
<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ 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">
private dv As DataView
private dt As New DataTable()
Private Sub Page_Load(sender As Object, e As System.EventArgs)
' Create a DataTable to use as the data source for
' the DataGrid.
dt.Columns.Add(new DataColumn("ItemNumber"))
dt.Columns("ItemNumber").Caption = "Item Number"
dt.Columns.Add(new DataColumn("Item"))
dt.Columns("ItemNumber").Caption = "Item"
dt.Columns.Add(new DataColumn("Price"))
dt.Columns("ItemNumber").Caption = "Price"
' Add some data to the DataTable.
Dim myDataRow As DataRow
Dim i As Integer
For i = 0 To 4
myDataRow = dt.NewRow()
myDataRow(0) = i
myDataRow(1) = "Item " & i.ToString()
myDataRow(2) = 1.23 * (i + 1)
dt.Rows.Add(myDataRow)
Next i
' Use the table to create a DataView.
dv = new DataView(dt)
'<Snippet4>
' Create hyperlink columns that contain the item name
' and price.
Dim nameCol As New HyperLinkColumn()
nameCol.DataNavigateUrlField = "ItemNumber"
nameCol.DataTextField = "Item"
nameCol.DataNavigateUrlFormatString = _
"DetailspageVB.aspx?id={0}"
nameCol.HeaderText = dt.Columns("Item").Caption
Dim priceCol As New HyperLinkColumn()
priceCol.DataNavigateUrlField = "ItemNumber"
priceCol.DataTextField = "Price"
priceCol.DataNavigateUrlFormatString = _
"DetailspageVB.aspx?id={0}"
priceCol.DataTextFormatString = "{0:c}"
priceCol.HeaderText = dt.Columns("Price").Caption
'</Snippet4>
' Add the new columns to the DataGrid.
DataGrid1.Columns.Add(nameCol)
DataGrid1.Columns.Add(priceCol)
' Set the DataView as the data source, and bind
' it to the DataGrid.
DataGrid1.DataSource = dv
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_ItemDataBound(sender As Object, _
e As System.Web.UI.WebControls.DataGridItemEventArgs)
Dim itemType As ListItemType = _
CType(e.Item.ItemType, ListItemType)
if itemType <> ListItemType.Header AndAlso _
itemType <> ListItemType.Footer AndAlso _
itemType <> ListItemType.Separator Then
'<Snippet5>
' Get the IntegerValue cell from the grid's column
' collection.
Dim currentCell As TableCell = _
CType(e.Item.Controls(0), TableCell)
DataGrid1.Columns(1).InitializeCell(currentCell, 1, _
ListItemType.Item)
'</Snippet5>
'<Snippet6>
' Add attributes to the cell.
currentCell.Attributes.Add("id", "currentCell" & _
e.Item.ItemIndex.ToString())
currentCell.Attributes.Add("OnClick", _
"Update_currentCell" & _
e.Item.ItemIndex.ToString() & _
"()")
'</Snippet6>
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>HyperLinkColumn Example</title>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<asp:DataGrid Runat="server" ID="DataGrid1" CellPadding="4"
AutoGenerateColumns="False" BorderStyle="None" GridLines="None">
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="Black">
</HeaderStyle>
</asp:DataGrid>
<p>Click on an item name or price to add the item to your order.</p>
</form>
</body>
</html>
<!--
This example demonstrates using a hyperlink column. The code below
should be copied into a file called DetailsPageCS.aspx. The file
should be stored in the same directory as the file HyperTextColumn.CS
described above.
-->
<!--
This example demonstrates using a hyperlink column. The code below
should be copied into a file called DetailsPageVB.aspx. The file
should be stored in the same directory as the file HyperTextColumnVB.aspx
described above.
-->
<%@ Page language="c#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data" %>
<!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>
<title>HyperLinkColumn Example</title>
<script runat="server">
private DataView dv;
private DataTable dt = new DataTable();
private void Page_Load(object sender, System.EventArgs e)
{
// Get the item value that was passed on the query string.
NameValueCollection myCollection = Request.QueryString;
string selectedItem = myCollection.Get("id");
Label1.Text = "Item " + selectedItem +
" has been added to your order.";
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<p><asp:Label id="Label1" runat="server">Label</asp:Label></p>
<p><asp:HyperLink id="HyperLink1" runat="server"
BorderColor="#8080FF" BorderStyle="Groove" ForeColor="Blue"
NavigateUrl="HyperTextColumnCS.aspx"> return to items page
</asp:HyperLink></p>
</form>
</body>
</html>
<%@ Page language="VB" AutoEventWireup="true" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data" %>
<!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>
<title>HyperLinkColumn Example</title>
<script runat="server">
Private dv As DataView
Private dt As New DataTable()
Private Sub Page_Load(sender As Object, e As System.EventArgs) _
Handles MyBase.Load
' Get the item value that was passed on the query string.
Dim myCollection As NameValueCollection = Request.QueryString
Dim selectedItem As String = myCollection.Get("id")
Label1.Text = "Item " & selectedItem & _
" has been added to your order."
End Sub
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>HyperLinkColumn Example</h3>
<p><asp:Label id="Label1" runat="server">Label</asp:Label></p>
<p><asp:HyperLink id="HyperLink1" runat="server"
BorderColor="#8080FF" BorderStyle="Groove" ForeColor="Blue"
NavigateUrl="HyperTextColumnVB.aspx"> return to items page
</asp:HyperLink></p>
</form>
</body>
</html>
설명
사용 하 여는 FormatDataNavigateUrlValue 로 지정 된 형식을 사용 하 여 데이터 바인딩된 URL 값의 형식을 지정 하는 방법의 DataNavigateUrlFormatString 속성입니다.
적용 대상
추가 정보
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET