参考下面的代码吧,利用OnItemDataBound事件来修改,需要完整代码可以去Wrox网站下载
Professional ASP.NET 1.0 的源码,在 Chapter 7 - List Controls and Data Binding 
里有个 Handling Data Binding Events in a DataList Object 的代码:)<%@Page Language="C#"%><%@Import Namespace="System.Data" %>
<%@ Register TagPrefix="wrox" TagName="connect" Src="..\global\connect-strings.ascx" %>
<%@ Register TagPrefix="wrox" TagName="getdataview" Src="..\global\get-dataview-control.ascx" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Handling Data Binding Events in a DataList Object</title>
<style type="text/css">
body, td {font-family:Tahoma,Arial,sans-serif; font-size:10pt}
input {font-family:Tahoma,Arial,sans-serif; font-size:9pt}
.heading {font-family:Tahoma,Arial,sans-serif; font-size:14pt; font-weight:bold}
.subhead {font-family:Tahoma,Arial,sans-serif; font-size:12pt; font-weight:bold; padding-bottom:5px}
.cite {font-family:Tahoma,Arial,sans-serif; font-size:8pt}.rHead {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial;
        font-size:14pt; font-weight:bold; padding:8px; color:green}
.rItem {font-family:Lucida Handwriting,Comic Sans MS,Tahoma,Arial,sans-serif;
        font-size:10pt}
.rFoot {font-family:Tahoma,Arial; font-size:8pt; padding:8px; color:darkgray}
.bigRed {font-family:Arial Black,sans-serif; font-size:12pt; font-weight:normal; color:red}</style></head>
<body bgcolor="#ffffff">
<span class="heading">Handling Data Binding Events in a DataList Object</span><hr />
<!---------------------------------------------------------------------------><%-- insert connection string script --%>
<wrox:connect id="ctlConnectStrings" runat="server" /><%-- insert the control that creates the DataSet --%>
<wrox:getdataview id="ctlDataView" runat="server" /><ASP:DataList id="MyDataList" runat="server" RepeatLayout="Table"
     OnItemDataBound="CheckTitle">  <HeaderTemplate>
    <div class="rHead">
      Some of the Latest Wrox Press Books<br />
      <img src="images/redrule.gif">
    </div>
  </HeaderTemplate>  <ItemTemplate>
    <div class="rItem">
      <b><ASP:Label id="TitleLabel" runat="server"
              Text='<%# DataBinder.Eval(Container.DataItem, "Title") %>' /></b><br />
      * ISBN: <%# DataBinder.Eval(Container.DataItem, "ISBN") %> &nbsp;
      Published: <%# DataBinder.Eval(Container.DataItem, "PublicationDate") %>
    </div>
  </ItemTemplate>  <FooterTemplate>
    <img src="images/redrule.gif">
    <div class="rFoot">
      For more information visit <a href="http://www.wrox.com">http://www.wrox.com</a>
    </div>
  </FooterTemplate></ASP:DataList><p /><!---------------------------------------------------------------------------><script language="c#" runat="server"> void Page_Load(Object sender, EventArgs e)
{
if (!Page.IsPostBack) // fill the DataList from a DataView object
{
// get connection string from ..\global\connect-strings.ascx user control
string strConnect = ctlConnectStrings.OLEDBConnectionString; // create a SQL statement to select some rows from the database
string strSelect = "SELECT * FROM BookList WHERE ISBN LIKE '%18610026%'"; // create a variable to hold an instance of a DataView object
DataView objDataView; // get dataset from get-dataset-control.ascx user control
objDataView = ctlDataView.GetDataView(strConnect, strSelect); if (objDataView == null)
return; // set the DataSource property of the DataList
MyDataList.DataSource = objDataView; // and bind the control to the data
MyDataList.DataBind();
}
}
void CheckTitle(Object objSender, DataListItemEventArgs objArgs)
{
// see what type of row (header, footer, item, etc.) caused the event
ListItemType objItemType = (ListItemType)objArgs.Item.ItemType; // only format the results if it's an Item or AlternatingItem event
if (objItemType == ListItemType.Item || objItemType == ListItemType.AlternatingItem)
{
// objArgs.Item.DataItem returns the data for this row of items
DataRowView objRowVals = (DataRowView)objArgs.Item.DataItem; // get the value of the Title column
string strTitle = objRowVals["Title"].ToString(); if (strTitle.IndexOf("Active Server Pages") != -1 || strTitle.IndexOf("ADO") != -1)
{
// get a reference to the "Title" ASP:Label control in this row
Label objLabel = (Label)objArgs.Item.FindControl("TitleLabel"); // add a message to this Label control
objLabel.Text += " &nbsp; <span class='bigRed'>Great for ASP Programmers!</span>";
}
}
}</script><!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

解决方案 »

  1.   

    类似的例子吧
    http://www.dotnetbips.com/displayarticle.aspx?id=107
      

  2.   

    我问的是在DataGrid《属性生成器》中《列》中《数据格式设置表达式》中如何写if 判断语句。?希望各位高手指点迷津!拜托了!
      

  3.   

    oracle中在sql语句中就可以控制 ,
    例如;decode(sdfl,'01','峰段','02','平段','03','谷段','00','全段',sdfl)
      

  4.   

    搂主问的是如何在DataGrid中的属性生成器里数据格式设置表达式应该怎么写if条件表达式,或是能不能写。(关注中)