在一个DataGrid中,我想根据绑定的某个字段IS_KERNEL  来判断 另一个绑定字段(调整顺序模板列)的显示  这样做 实现不了,哪位能帮帮忙  <%# if(DataBinder.Eval(Container.DataItem,"IS_KERNEL").ToString() =="Y" && IsBusinessCenter=true) {%>
      <asp:TemplateColumn HeaderText="调整顺序" ItemStyle-HorizontalAlign=Center> 
<HeaderStyle HorizontalAlign="Center" CssClass="tit_list_01" Width=10%></HeaderStyle>
<ItemTemplate>
<a href="ChangeSortNo.aspx?pid=<%#DataBinder.Eval(Container.DataItem,"Pkid")%>&isUp=1">
<img src="../../images/icon_up.gif"></a>&nbsp;&nbsp;
<a href="ChangeSortNo.aspx?pid=<%#DataBinder.Eval(Container.DataItem,"Pkid")%>&isUp=0">
<img src="../../images/icon_down.gif"></a>
</ItemTemplate>
</asp:TemplateColumn><%}%>

解决方案 »

  1.   

    用三元运算试试。
    <%# Eval("Name").ToString()=="1"?"上学期":"下学期" %>
      

  2.   

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.Cells[0].Text == "Y")//IS_KERNEL
                {
                    e.Row.Cells[1].Visible = true;
                }
                else
                {
                    e.Row.Cells[1].Visible = false;
                }            //或者放在同一个单元格里面,用一个Lable来在绑定IS_KERNELLBL的值
                Label lb = (Label)e.Row.Cells[2].FindControl("IS_KERNELLBL");
                if (lb.Style.Value == "Y")
                {
                    e.Row.Cells[2].Visible = true;
                    lb.Visible = false;
                }
                else
                {
                    e.Row.Cells[1].Visible = false;
                }
            }        
             
        }
      

  3.   

    <%# Eval("Name").ToString()=="1"?"上学期":"下学期" %>
    //这里的Name可以是另一列的。
    我这个例子就是当结婚之后就不能再设置成结婚了,和你说的功能很类似的。
      

  4.   

    主要就是使用模版列,
    核心代码如下:<asp:TemplateField HeaderText="婚否">
                        <ItemTemplate>
                            <asp:LinkButton CommandArgument='<%# Eval("Id") %>' Enabled='<%# Boolean.Parse(Eval("Married").ToString())==true?false:true %>' Text="设为结婚" runat="server" OnCommand="SetMarried"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>因为你使用的是DataGrid,和GridView有些不太一样,但是大体思路是一致的。
    详见:http://blog.csdn.net/zhoufoxcn/archive/2007/06/13/1650952.aspx
      

  5.   

    在DataGrid1_ItemDataBound里判断字段值。设置是否隐藏列。
    if(e.Item.Cells[1].Text.ToString().Trim()=="")
    {
    DataGrid1.Columns[2].Visible = False
    }