Hello Gary,
I think the behavior for InVisible columns in DataGrid and GridView
control
should be identical. You can access them in ItemCreated(RowCreated) and
ItemDataBound(RowDataBound) event. I'm not sure what's the problem in
your
certain page, one common issue is that we try finding control without
first
detect the RowType(ItemType) of each Item/Row. Anyway, here is a test page
which works on my local side, you can also refer to it for your testing
===========aspx===================
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName] FROM
[Categories]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1"
OnRowCreated="GridView1_RowCreated"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:TemplateField HeaderText="HiddenColumn"
Visible="false">
<asp:Button ID="btn1" runat="server" Text="Button1"
/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<br />
<br />
<asp
ataGrid ID="DataGrid1" runat="server"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
OnItemCreated="DataGrid1_ItemCreated"
OnItemDataBound="DataGrid1_ItemDataBound">
<Columns>
<asp:BoundColumn DataField="CategoryID"></asp:BoundColumn>
<asp:BoundColumn
DataField="CategoryName"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="HiddenColumn"
Visible="false" >
<ItemTemplate>
<asp:TextBox ID="txt2"
runat="server"></asp:TextBox>
<asp:Button ID="btn2" runat="server" Text="Button"
/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid></div>
</form>
==================================
==========codebehind=================
public partial class Part1_ASPSQLPAGE : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowCreated:" + txt);
}
}
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Control txt = e.Row.FindControl("txt1");
Response.Write("<br/>GridView1_RowDataBound:" + txt);
}
}
protected void DataGrid1_ItemCreated(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemCreated:" + txt);
}
}
protected void DataGrid1_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
Control txt = e.Item.FindControl("txt2");
Response.Write("<br/>DataGrid1_ItemDataBound: " + txt);
}
}
}
=================================
Hope this helps.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.