日期:2014-05-18  浏览次数:20457 次

绑定repater空件的问题
数据表了有一个审核状态字段,是bool型,我想让真值时给item里的一个label绑定为"通过"假时为"未通过",请看下我下面的代码哪不对,
 <ItemTemplate>
  <tr>
  <td><%#((DataRowView)Container.DataItem)["ID"]%></td>
  <td><%#((DataRowView)Container.DataItem)["Name"]%></td>
  <td><a href="#">查看</a></td>
  <td><a href="#">修改</a></td>
  <td><%#((DataRowView)Container.DataItem)["LoginTime"] %></td>
  <td>
  <asp:Label ID="lblState" runat="server" Text="Label"></asp:Label></td>
  <td><%#((DataRowView)Container.DataItem)["State"] %></td>
  <td>&nbsp;</td>
  </tr>
  


  protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
  {



  if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==

ListItemType.AlternatingItem)
  {

  DataRowView rowv = (DataRowView)e.Item.DataItem;

  Label lblState = (Label)e.Item.FindControl("lblState");

  Boolean state = Convert.ToBoolean(rowv["State"]);
  if (state)
  {
  lblState.Text = "通过";
   
  }
  else
  {
  lblState.Text = "未审核";
   
  }

  }

  }  





------解决方案--------------------
SQL code

select case State when 1 then '审核通过' else '审核失败' end case as strState from table

------解决方案--------------------
<%#Show(((DataRowView)Container.DataItem)["State"] ) %>
============================================================
public string Show(object state){
if(Convert.ToBoolean(state))
return "通过";
else
return "未通过";
}
------解决方案--------------------
在较早,曾专为此显示格式录了一个影片,不过是用GridView来做的,但其方法,完全可以应用于Reater或是DataList之上,请参考:

http://download.csdn.net/source/204062