// Create sample data for the DataList control. DataTable dt = new DataTable(); DataRow dr;
// Define the columns of the table. dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32))); dt.Columns.Add(new DataColumn("StringValue", typeof(String))); dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
// Populate the table with sample values. for (int i = 0; i < 9; i++) { dr = dt.NewRow();
dr[0] = i; dr[1] = "Description for item " + i.ToString(); dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr); }
DataView dv = new DataView(dt); return dv; }
void Page_Load(Object sender, EventArgs e) { // Load sample data only once, when the page is first loaded. if (!IsPostBack) { ItemsList.DataSource = CreateDataSource(); ItemsList.DataBind(); } } void Item_Bound(Object sender, DataListItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { // Retrieve the Label control in the current DataListItem. Label PriceLabel = (Label)e.Item.FindControl("PriceLabel"); // Retrieve the text of the CurrencyColumn from the DataListItem // and convert the value to a Double. Double Price = Convert.ToDouble( ((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString()); // Format the value as currency and redisplay it in the DataList. PriceLabel.Text = Price.ToString("c"); } }
<ItemTemplate> <asp:Label ID="lbl" Runat =server> <%# asdf(databinder.eval(container.dataitem,"employeeid")) %> </asp:Label></ItemTemplate> Public Function asdf(ByVal tempID As Integer) As String if (tempID=1) then asdf="<a href='showattach.aspx?attachid=tempid'>" else asdf="" End Function
<%@ Page Language="C#" AutoEventWireup="True" %>
<%@ Import Namespace="System.Data" %>
<html>
<script runat="server">
ICollection CreateDataSource()
{
// Create sample data for the DataList control.
DataTable dt = new DataTable();
DataRow dr;
// Define the columns of the table.
dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
// Populate the table with sample values.
for (int i = 0; i < 9; i++)
{
dr = dt.NewRow();
dr[0] = i;
dr[1] = "Description for item " + i.ToString();
dr[2] = 1.23 * (i + 1);
dt.Rows.Add(dr);
}
DataView dv = new DataView(dt);
return dv; }
void Page_Load(Object sender, EventArgs e)
{ // Load sample data only once, when the page is first loaded.
if (!IsPostBack)
{
ItemsList.DataSource = CreateDataSource();
ItemsList.DataBind();
} } void Item_Bound(Object sender, DataListItemEventArgs e)
{ if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{ // Retrieve the Label control in the current DataListItem.
Label PriceLabel = (Label)e.Item.FindControl("PriceLabel"); // Retrieve the text of the CurrencyColumn from the DataListItem
// and convert the value to a Double.
Double Price = Convert.ToDouble(
((DataRowView)e.Item.DataItem).Row.ItemArray[2].ToString()); // Format the value as currency and redisplay it in the DataList.
PriceLabel.Text = Price.ToString("c"); } }
</script>
<body>
<form runat=server> <h3>DataList ItemDataBound Example</h3>
<asp:DataList id="ItemsList"
BorderColor="black"
CellPadding="5"
CellSpacing="5"
RepeatDirection="Vertical"
RepeatLayout="Table"
RepeatColumns="3"
ShowBorder="True"
OnItemDataBound="Item_Bound"
runat="server"> <HeaderStyle BackColor="#aaaadd">
</HeaderStyle> <AlternatingItemStyle BackColor="Gainsboro">
</AlternatingItemStyle> <HeaderTemplate> List of items </HeaderTemplate>
<ItemTemplate> Description: <br>
<%# DataBinder.Eval(Container.DataItem, "StringValue") %> <br> Price:
<asp:Label id="PriceLabel"
runat="server"/> </ItemTemplate>
</asp:DataList>
</form>
</body>
</html>
<asp:Label ID="lbl" Runat =server>
<%# asdf(databinder.eval(container.dataitem,"employeeid")) %>
</asp:Label></ItemTemplate> Public Function asdf(ByVal tempID As Integer) As String
if (tempID=1) then
asdf="<a href='showattach.aspx?attachid=tempid'>"
else
asdf=""
End Function
{
if(e.Item .ItemType ==ListItemType.Item || e.Item .ItemType==ListItemType.AlternatingItem )
{
String f=e.Item.Cell[5].Text.Trim();
if(f=="1"){ e.Item.Cells[5].Text="<a href =\"showattach.aspx?attachid="+f+" \" >查看附件</a>"
}
else
{
e.Item.Cells[5].Text="";
}
}}
这个不行啊
function (value)
{
}