Thanks for Brock's good suggestions.
Hi Arun,
IMO, if your want to individually hidden some certain controls in a
columns, I think at first we should choose TemplateColumn since its the
most flexible one. Then, we should explicitly assign an "ID" for those
controls we want to reference later. After that, we can access those
controls in DataGrid's ItemDataBound/ItemCreated event or in any other
control (on the same page)'s post back event and modify those controls'
propety.
For example, suppose we have the following datagrid template:
<form id="Form1" method="post" runat="server">
<asp
ataGrid id="dgLink" runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="title" HeaderText="Title"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Link">
<ItemTemplate>
<asp:HyperLink id="hlVisit" runat="server" NavigateUrl='<%#
((System.Data.DataRowView)Container.DataItem)[1] %>'>Visit</asp:HyperLink>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp
ataGrid>
<asp:Button id="btnSubmit" runat="server" Text="Submit"></asp:Button>
</form>
Then, we can hidden the hyperlink controls in some certain rows throw
ItemDataBound event or in the button's postback event like below:
======= using itemdatabound event=========
private void dgLink_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
if(e.Item.ItemIndex == 4)
{
HyperLink hlVisit = e.Item.FindControl("hlVisit") as HyperLink;
if(hlVisit != null)
{
hlVisit.Visible = false;
}
}
}
}
=====using button's click event=========
private void btnSubmit_Click(object sender, System.EventArgs e)
{
DataGridItem dgi = dgLink.Items[4];
HyperLink hlVisit = dgi.FindControl("hlVisit") as HyperLink;
if(hlVisit != null)
{
hlVisit.Visible = false;
}
}
Hope also helps. Thanks,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)