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

★ 50分,再次请求正确的写发;<%# %>中这样写对吗?
Visible= ' <%#   (Eval( 'r_Type ')).Tostring().Substring(0,5)== "image "?true:false   %> '
---
目的:获取当前绑定值的前5位字符串,如果是image就将该控件的Visible属性设置为True,上述方法并不对,仅供参考;
·请高人写出正确的方法来!

------解决方案--------------------
既然是设置服务器控件的Visible,在绑定事件里判断很简单,也好控制
例如


protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView drv = (System.Data.DataRowView)e.Row.DataItem;
//如果数据源是DataReader,则写成 System.Data.Common.DbDataRecord drv = (System.Data.Common.DbDataRecord)e.Row.DataItem;
TextBox TextBox1 = (TextBox)e.Row.FindControl( "TextBox1 ");
if (TextBox1 != null)
{
TextBox1.Visible = (drv[ "r_Type "].ToString().ToLower().Substring(0,5)== "image "?true:false;
}
}
}

------解决方案--------------------
是挺简单的,哈哈