如题:
protected void gvMusic_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[0].Attributes.Add("style", "display:none");
    }这样就无法显示分页了,因为第一列是ID,所以想隐藏起来。请问有什么办法能使用分页呢?

解决方案 »

  1.   

    ID应该使用 DataKeyNames="FiledID" 属性设置,程序在需要时使用 gvMusic.DataKeys[rowIndex].value 获取
      

  2.   

    楼上,我也不想啊,问题是我这每一行还要加个js事件:
    e.Row.Attributes.Add("onClick","alert('" + e.Row.Cells[0].Text.ToString() + "')");
    如果不用e.Row.Cells[0].Attributes.Add("style",   "display:none"); 来隐藏ID列,那还有什么办法呢?
      

  3.   

    e.Row.Attributes 这个应该在  DataBound事件中吧, 如果数据源是DataTable,可以用:
    DataRowView drv=(DataRowView)e.Item.DataItem 来获取当前的数据源int keyID=drv["FiledID"];