问题简单,快来抢分.......
我再DataGrid中有一个模板列
<ItemTemplate>
<input type= "button " value= "更新 "id= "btnUpdate " onClientClick= 'openDialogWindow( <%# DataBinder.Eval(Container, "DataItem.iEnterpriseID ") %> ) '>
</ItemTemplate>
我在ItemDataBound事件中,还要根据条件判断 是否显示这个按钮。
所以 我加了 runat= "server ".可是加了之后
<%# DataBinder.Eval(Container, "DataItem.iEnterpriseID ") %> 不会显示绑定后的数字,原样输出了。
请问各位改怎么办呢?谢谢各位了。。
------解决方案-------------------- 模板列里的内容:
<%# GetNewType(Container.DataItem, "ID ", "Title ", "Content ", "NewsPath ", "NewsType ")%>
后台转换
public string GetNewType(object container,string newsidfield,string newstitlefield, string contentfield, string newspathfield,string newstypefield)
{
string Return = " ";
string Newsidfield = DataBinder.GetPropertyValue(container, newsidfield).ToString();
string Newstitlefield = DataBinder.GetPropertyValue(container, newstitlefield).ToString();
string Contentfield = DataBinder.GetPropertyValue(container, contentfield).ToString();
string Newspathfield = DataBinder.GetPropertyValue(container, newspathfield).ToString();
string Newstypefield = DataBinder.GetPropertyValue(container, newstypefield).ToString();
if (Newstypefield == "0 ")
{
// Return = " <a href=\ "#\ " style=\ "text-decoration:none;cursor:hand;\ " onclick=\ "ShowNews( " + Newspathfield + ");\ " title= " + Newstitlefield + "> " + Newstitlefield + " </a> ";
Return = " <a href=\ "#\ " class=\ "TextWhiteL170\ " style=\ "text-decoration:none;cursor:hand;\ " onclick=\ "MM_openBrWindow( ' " + Newspathfield + " ');\ " title= " + Newstitlefield + "> " + Newstitlefield + " </a> ";
}
if (Newstypefield == "1 ")
{
Return = " <a href=\ "#\ " class=\ "TextWhiteL170\ " style=\ "text-decoration:none;cursor:hand;\ " onclick=\ "MM_openBrWindowByID( ' " + Newsidfield + " ');\ " title= " + Newstitlefield + "> " + Newstitlefield + " </a> ";
}
return Return;
}
把我这改成你自己的就 OK了,我这是 <a> 你改为input应该一样ok
------解决方案--------------------private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType==System.Web.UI.WebControls.ListItemType.Item||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.AlternatingItem||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.EditItem||e.Item.ItemType==System.Web.UI.WebControls.ListItemType.SelectedItem)
{System.Web.UI.WebControls.HyperLink link = (HyperLink)e.Item.Cells[2].Controls[0];
link.ToolTip=link.Text.ToString().Trim();
link.Text = link.Text.Length> 6?link.Text.ToString().Trim().Substring(0,5)+ "... ":link.Text.ToString().Trim();
}
}
------解决方案--------------------劫分!
------解决方案--------------------如果模板是e.Item.Cells[2]
System.Web.UI.WebControls.HyperLink link = (HyperLink)e.Item.Cells[2].Controls[0];
这个是在 模板里面放了一个HyperLink 的控件,这样就可以把它找出来,可以更改它的属性了,