有一个含checkbox的gridview分页列表,代码如下:
<asp:GridView ID="GVDemo" runat="server" AllowPaging="true" Width="100%" DataKeyNames="id" PageSize="15" AutoGenerateColumns="False" GridLines="None" OnRowDataBound = "GridView_RowDataBound">
<FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" />
<RowStyle CssClass="body" />
<Columns>
<asp:TemplateField >
<ItemStyle CssClass="checkbox" />
<ItemTemplate>
<asp:CheckBox ID="checkids" runat="server"/>
         <asp:Label ID="id" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "id")%>' Visible="false"></asp:Label> 
        </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="类型">
<ItemStyle CssClass="type" Width="100px" />
<ItemTemplate>
<a href="addtype.aspx?action=modify&id=<%# DataBinder.Eval(Container.DataItem, "typeid")%>">[<%# DataBinder.Eval(Container.DataItem, "typename")%>]</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate></PagerTemplate>
<PagerStyle BackColor="#5C9DC5" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle Height="20px" CssClass="title" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>-----------------------------------------------------------------------
SQL语句:
select id,typeid,typename,checkboxflag from table1现在想根据字段checkboxflag的内容来控制gridview中的checkids是否显示,如何实现

解决方案 »

  1.   

     protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)  
        {
          if ( e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
          {
            // 隐藏FLG 标识的列
            if ((满足Flg 条件))
            {
                e.Row.Cells[m].Visible = false;   // m为满足Flg隐藏的列。
            }
          }
        }
      

  2.   


    <ItemTemplate>
    <asp:CheckBox ID="checkids" runat="server" Visible='<%# Convert.ToBoolen(<%#Eval("checkboxflag")%>) %>'/>
            <asp:Label ID="id" runat="server" Text=' <%# DataBinder.Eval(Container.DataItem, "id")%>' Visible="false"> </asp:Label>
            </ItemTemplate> 
      

  3.   

     if ((满足Flg 条件))  这里怎么写?
      

  4.   

    修改
    checked的帮定表达式Eval里加if语句
      

  5.   

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)  
        { 
          if ( e.Row.RowType == DataControlRowType.DataRow ) 
          { 
            if (((DataRowView)Container.DataItem).Row["checkboxflag"].ToString=="具体的值")
            { 
                e.Row.Cells[m].Visible = false;
            } 
          } 
        }
      

  6.   

    to:changke18
    提示:上下文中不存在Container
    to:ojlovecd
    <asp:CheckBox ID="checkids" runat="server" Visible=' <%# Convert.ToBoolen( <%#Eval("checkboxflag")%>) %>'/> 这个写法总是报错
      

  7.   

    Visible='<%# Convert.ToBoolean(Eval("checkboxflag")) %>'
      

  8.   

    好了,谢谢各位
    Visible=' <%# Convert.ToBoolean(Eval("checkboxflag")) %>'