首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

★ 50分,再次请求正确的写发;<%# %>中这样写对吗?该怎么处理

2012-02-02 
★ 50分,再次请求正确的写发;%# %中这样写对吗?Visible%#(Eval( r_Type )).Tostring().Substring(0,5)

★ 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;
}
}
}

[解决办法]
是挺简单的,哈哈

热点排行