你是不是在itemdatabound事件里操作?

解决方案 »

  1.   

    <asp:GridView ID="gvComUnion" runat="server" AllowPaging="True"   AutoGenerateColumns="False"
           BackColor="White" BorderColor="#3366CC" BorderStyle="Solid" BorderWidth="1px"
           CellPadding="2" Font-Size="12px" HorizontalAlign="Left" OnPageIndexChanging="gvComUnion_PageIndexChanging" 
           OnRowEditing="gvComUnion_RowEditing" PageSize="12" Width="545px" OnRowDataBound="gvComUnion_RowDataBound" OnLoad="gvComUnion_Load" OnRowCreated="gvComUnion_RowCreated" Font-Names="宋体" OnSelectedIndexChanged="gvComUnion_SelectedIndexChanged" AllowSorting="True" >
           <PagerSettings FirstPageText="第一页" LastPageText="最后一页" Mode="NextPreviousFirstLast"
             NextPageText="下一页" PreviousPageText="上一页"/>
           <FooterStyle BackColor = "#EFEFEF" ForeColor = "#000D47"/>
            <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID">
            <ItemStyle HorizontalAlign="Left"/>
                    <HeaderStyle Width="30px"/>
                </asp:BoundField>/////--------------------第一列
              <asp:TemplateField>
                    <HeaderTemplate>
                      <asp:CheckBox ID="ckbSelect" runat="server" Text="全选" OnCheckedChanged="CheckAll"  Width="40px" AutoPostBack="True"/>
                    </HeaderTemplate>
                    <ItemTemplate>
                      <asp:CheckBox ID="ItemCheckBox" runat="server" />
                    </ItemTemplate>
                  </asp:TemplateField>/////--------------------第二列            <asp:BoundField DataField="COMID"  HeaderText="编号">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="30px" />
                </asp:BoundField>
                <asp:BoundField DataField="COMNAME"  HeaderText="单位名称">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="100px" />
                </asp:BoundField>
                    
                <asp:BoundField DataField="COMINLOW" HeaderText="所有制">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="90px" />
                </asp:BoundField>
                <asp:BoundField DataField="BUSINESS" HeaderText="行业">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="90px" />
                </asp:BoundField>
                <asp:BoundField DataField="DISTRICT" HeaderText="所在区">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="40px" />
                </asp:BoundField>
                <asp:BoundField DataField="STATUS" HeaderText="状态">
                    <ItemStyle HorizontalAlign="Left" />
                    <HeaderStyle Width="30px" />
                </asp:BoundField>
                <asp:CommandField EditText="详细信息" HeaderText="详细信息" ShowEditButton="True">
                    <HeaderStyle Width="60px" />
                </asp:CommandField>        </Columns>        <RowStyle ForeColor="#003399" HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCFF99" />
            <PagerStyle BackColor="#EFEFEF" ForeColor="#003399" HorizontalAlign="Right" />
            <HeaderStyle BackColor="#003399" BorderStyle="None" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="#EFEFEF" />
            
        </asp:GridView>
    这样写的,运行后始终看不到第一列。
      

  2.   

    protected void gvComUnion_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               
                e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#FFEFD5'");
                          e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor");                  }
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.Cells[3].Text).Length > 8 && (e.Row.Cells[3].Text!="&nbsp;"))
                {
                    e.Row.Cells[3].Text = (e.Row.Cells[3].Text).Substring(0, 8) + "...";
                }
                if ((e.Row.Cells[4].Text).Length > 6 && (e.Row.Cells[4].Text != "&nbsp;"))
                {
                    e.Row.Cells[4].Text = (e.Row.Cells[4].Text).Substring(0, 6) + "...";
                }
                if ((e.Row.Cells[5].Text).Length > 6 && (e.Row.Cells[5].Text!="&nbsp;"))
                {
                    e.Row.Cells[5].Text = (e.Row.Cells[5].Text).Substring(0, 6) + "...";
                }
            }
                }
    有什么问题吗?
      

  3.   

    有进展了
    在 protected void gvComUnion_RowDataBound(object sender, GridViewRowEventArgs e)
    加一句
     e.Row.Cells[0].Visible = true;
    就能显示了,问题是为什么不加就不能显示啊?
      

  4.   

    http://hi.baidu.com/boshiclub
    我们一起创业,我们一起发财,我们一起快乐,我们一起努力!