if (e.Row.RowType == DataControlRowType.DataRow)
{
switch(e.Row.Cells[11].Text)
{
case "1":
  e.Row.Cells[11].Text="<font blue=red>自辦</font>";
  break;
case "2":
  e.Row.Cells[11].Text="<font blue=blue>委辦</font>";
  break;
case "3":
  e.Row.Cells[11].Text="<font blue=yellow>派外</font>";
  break;
}
}上面的代码,对1实现不了,对2就可以,问题出在哪?
1,<asp:TemplateField headertext="培訓類型">
<itemtemplate><%#Eval("TrainingKind")%></itemtemplate>
<edititemtemplate>
<asp:DropDownList runat="server" ID="ddlTrainingKind">
        <asp:ListItem Text="自辦" Value="1"/>      
        <asp:ListItem Text="委辦" Value="2"/>      
        <asp:ListItem Text="派外" Value="3"/>      
</asp:DropDownList>
</edititemtemplate>
</asp:TemplateField>
2,<asp:boundfield headertext="培訓類型" datafield="TrainingKind"/>

解决方案 »

  1.   

    调试看看 e.Row.Cells[11].Text 的值
      

  2.   

    是不是模板了
        如果是 要用findeContor
      

  3.   

    我在TemplateField內直接用了<itemtemplate><%#Eval("TrainingKind")%></itemtemplate>沒用控件之類的,不加Label可行嗎?
      

  4.   

    case "1":
    e.Row.Cells[11].Text="<font blue=red>自辦</font>";
    break;
    blue =red ????这是什么???应该是color 吧。
      

  5.   


    哦,這個是寫錯了,是color,謝謝,不過不影響改變Cells的內容
      

  6.   

    .Row.Cells[11].Text="<font blue=red>自辦</font>";
    .Row.Cells[11].Text="<font color="red">自辦</font>";
      

  7.   


    关键不在这,这只是个手误,修改后同样不能。
    <itemtemplate><%#Eval("TrainingKind")%></itemtemplate>
    e.Row.Cells[11].Text为什么会是空值呢,我查看源码是有数据呢
    看到部分的如下:
    <td>3</td>