GridView列中Visible="False"的異同
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="LblGoodsID" runat="server" Text='<%# bind("cGoodsID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="cGoodsID" Visible="False" />
protected void OnUpdate(object sender, EventArgs e)
{
GridViewRow t = (GridViewRow)(((ImageButton)sender).Parent.Parent);
Label LblGoodsID = (Label)t.FindControl("LblGoodsID");
Response.Write(LblGoodsID.Text);
Response.Write(t.Cells[1].Text);
}
同是Visible="False"第一個可以打印出來.第二個則沒有被打印出來
如果要在GridView 控件中隱藏不必要的列,使用visible="false"后 你就無法取得這列的值了.
解決問題的方法很簡單:
--------------------------------------------------
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[0].Visible=false;
e.Row.Cells[3].Visible=false;
}
}

浙公網安備 33010602011771號