日期:2014-05-18  浏览次数:20513 次

又一个Gridview的问题
比如一个表里有6个字段
现在我Select出来记录   到一个dataset中(select*)
然后G1.DataSource   =   dataset.Tables(0)
G1.DataBind()
请问这个时候我不想显示某些列该怎么做?
请问这个时候如何更改Columns的HeaderText?

谢谢!!

------解决方案--------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[1].Visible = false;//设置你要隐藏的列

if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].Text = "ffff ";//更改header的text
}
}
------解决方案--------------------
gridview中可以設置:
<asp:GridView ID= "gvAllTask " runat = "server " DataKeyNames = "taskid " BorderWidth = "0px " AutoGenerateColumns = "false " Width = "100% " AllowPaging = "true " PageSize =2
OnPageIndexChanging= "gvAllTask_PageIndexChanging ">

<Columns >
<asp:TemplateField HeaderImageUrl = "~/Images/delete.gif " >
<ItemTemplate >
<asp:CheckBox ID= "chkDel " runat = "server " />

<input type= "hidden " id= "hidTaskId " runat = "server " value= <%#Eval( "taskid ") %> />
</ItemTemplate>
<ItemStyle Width = "20px " HorizontalAlign= "Left " />
</asp:TemplateField>

<asp:HyperLinkField HeaderText = "編號 " DataTextField = "taskid " DataNavigateUrlFormatString= "detail.aspx?id={0} " DataNavigateUrlFields = "taskid " Target = "_blank " >


</asp:HyperLinkField>

<asp:BoundField HeaderText = "類別 " DataField = "taskType ">


</asp:BoundField>
<asp:BoundField HeaderText= "區域 " DataField = "typedomain " >


</asp:BoundField>

<asp:BoundField HeaderText= "工號 " DataField = "userid ">


</asp:BoundField>

<asp:BoundField HeaderText= "姓名 " DataField = "username ">


</asp:BoundField>
<asp:BoundField HeaderText= "時間 " DataField = "createdate ">


</asp:BoundField>
<asp:BoundField HeaderText= "工程師 " DataField = "engineer ">


</asp:BoundField>
<asp:BoundField HeaderText= "狀況 " DataField = "status " >


</asp:BoundField>


</Columns>
<HeaderStyle BackColor= "#C0C0FF " />
</asp:GridView>
------解决方案--------------------
Up一下。
protecte