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

gridview中根据列内容反回值的问题,急..在线等...........
放在UpdatePanel中的gridview,,后台数据绑定后,其中一列内容为
<asp:TemplateField ItemStyle-Width="16%" ItemStyle-HorizontalAlign="Center">
<ItemTemplate><%# DataBinder.Eval(Container.DataItem, "id")%></ItemTemplate>
</asp:TemplateField>


打算根据此ID反回不同的内容


于是在后台写个

public string getqx(string strqx)
  {
  string getqxname = "";
  if (strqx == "1")
  {
  getqxname = "abc";
  }
  return getqxname;
  return string.Empty;
  }

于是,<%# DataBinder.Eval(Container.DataItem, "id")%>改为<%# getqx(DataBinder.Eval(Container.DataItem, "id").ToString())%>



但不管id为几,前台都是空内容,,,,,,为什么啊?怎么解决啊?应该怎么写啊?

------解决方案--------------------
你这样
public string getqx(string strqx)
{
string getqxname = "";
if (strqx.Trim() == "1")
{
getqxname = "abc";
}
else
{
getqxname = "不是1";
}
return getqxname;
}

看看显示什么

asp.net2.0之后可以直接写
<%# getqx(Eval("id").ToString())%>