数据控件绑定技巧

代码
<asp:DataList ID="Mylist" runat="server" HorizontalAlign="center" Width="98%">
<HeaderTemplate>
<table id="t1" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="3">
</td>
<td width="30" align="center">
<%=xmldoc.SelectSingleNode("//UI/ID").InnerText %>
</td>
<td>
<%=xmldoc.SelectSingleNode("//UI/OUTFIT_NO").InnerText %>
</td>
<td width="80">
<%=xmldoc.SelectSingleNode("//UI/STATUS_NO").InnerText%>
</td>
<td width="100">
<%=xmldoc.SelectSingleNode("//UI/CHECK_STATUS").InnerText %>
</td>
<td width="80">
<%=xmldoc.SelectSingleNode("//UI/USER_NAME").InnerText %>
</td>
<td width="100">
<%=xmldoc.SelectSingleNode("//UI/CHECK_DATE").InnerText %>
</td>
<td width="100">
<%=xmldoc.SelectSingleNode("//UI/NEXT_DATE").InnerText %>
</td>
<td width="3">
</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table id="t2" border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td width="3">
</td>
<td width="30" align="center">
<%# (Container.ItemIndex + 1).ToString("00") + "." %>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem, "OUTFIT_NO")%>
</td>
<td width="80">
<%# GetState(Container)%>
</td>
<td width="100">
<%#DataBinder.Eval(Container.DataItem,"CHECK_STATUS") %>
</td>
<td width="80">
<%#DataBinder.Eval(Container.DataItem,"USER_NAME") %>
</td>
<td width="100">
<%#DataBinder.Eval(Container.DataItem,"CHECK_DATE","{0:yyyy-MM-dd}") %>
</td>
<td width="100">
<%#DataBinder.Eval(Container.DataItem,"NEXT_DATE","{0:yyyy-MM-dd}") %>
</td>
<td width="3">
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

 

 

代码
public string GetState(DataListItem data)
{
string checkState = "";
string nextDate = "";

DataRowView view
= (DataRowView)data.DataItem;
checkState
= view.Row["CHECK_STATUS"].ToString();
nextDate
= view.Row["NEXT_DATE"].ToString();
if (checkState == "P" && DateTime.Parse(nextDate) > DateTime.Now)
{
return "\u53EF\u7528";
}
else
{
return "\u4E0D\u53EF\u7528";
}

}

 

posted @ 2010-03-02 11:49  i_mint  阅读(218)  评论(0编辑  收藏  举报