隐藏列有几种方法:
一
先要在GridView1的aspx文件中,设置好各个列比如:
<asp:GridView ID="gvOutDialerHistoryRecord" runat="server" Width="100%" AutoGenerateColumns="False" AllowPaging="True" OnRowCommand="gvOutDialerHistoryRecord_RowCommand" DataKeyNames="ServiceNum,Orientation,Phone_Num,Call_StartTime,Call_EndTime,CallEndFlag,ProjectName,CustomerName,Result,Seat,RecordURL" OnRowCreated="gvOutDialerHistoryRecord_RowCreated" OnPageIndexChanging="gvOutDialerHistoryRecord_PageIndexChanging" OnRowEditing="gvOutDialerHistoryRecord_RowEditing" >
<Columns>
<asp:BoundField HeaderText="服务编号" DataField="ServiceNum" />
<asp:BoundField HeaderText="服务方向" DataField="Orientation" />
<asp:BoundField HeaderText="被叫号码" DataField="Phone_Num" />
<asp:BoundField HeaderText="拨打时间" DataField="Call_StartTime" />
<asp:BoundField HeaderText="挂机时间" DataField="Call_EndTime" />
<asp:BoundField HeaderText="挂机标识" DataField="CallEndFlag" />
<asp:BoundField HeaderText="外拨项目" DataField="ProjectName" />
<asp:BoundField HeaderText="外拨样本" DataField="CustomerName" />
<asp:BoundField HeaderText="访问结果" DataField="Result" />
<asp:BoundField HeaderText="服务坐席" DataField="Seat" />
<asp:BoundField HeaderText="录音文件地址" DataField="RecordURL" />
<asp:CommandField HeaderText ="操作" ShowSelectButton="True" ButtonType="Image" SelectImageUrl="~/images/image0010.jpg" UpdateImageUrl="~/images/image0017.jpg" AccessibleHeaderText="操作" EditImageUrl="~/images/image0017.jpg" ShowEditButton="True" />
</Columns>
</asp:GridView>
然后再C#代码里 写上下面的就可以了
this.GridView1.Columns[10].Visible = true;
this.GridView1.DataSource = ds.Tables[0].DefaultView;
this.DataBind();
this.GridView1.Columns[10].Visible = false;
二、把绿色的地方 加到代码里就可以了 可能引号不要用 忘了 呵呵
<Columns>
<asp:BoundField HeaderText="服务编号" DataField="ServiceNum" />
<asp:BoundField HeaderText="服务方向" DataField="Orientation" />
<asp:BoundField HeaderText="被叫号码" DataField="Phone_Num" />
<asp:BoundField HeaderText="拨打时间" DataField="Call_StartTime" />
<asp:BoundField HeaderText="挂机时间" DataField="Call_EndTime" />
<asp:BoundField HeaderText="挂机标识" DataField="CallEndFlag" />
<asp:BoundField HeaderText="外拨项目" DataField="ProjectName" />
<asp:BoundField HeaderText="外拨样本" DataField="CustomerName" />
<asp:BoundField HeaderText="访问结果" DataField="Result" />
<asp:BoundField HeaderText="服务坐席" DataField="Seat" />
<asp:BoundField HeaderText="录音文件地址" DataField="RecordURL" Visible ="false"/>
</Columns>
三、使用行绑定事件来隐藏,这种方法可以不用在.aspx文件中写类似第一第二种方法的html
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if ((e.Row.RowType == DataControlRowType.DataRow) || (e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.Footer))
{
e.Row.Cells[3].Visible = false;
}
}
获取隐藏列值
上面隐藏的方法 本人只有获取 第一中隐藏后的值 第二种有待研究
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
int iRowIndex = Convert.ToInt32(e.CommandArgument);
this.GridView1.Rows[iRowIndex].Cells[10].Text.ToString(); //这部分就是获取值
}