|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Datagrid Hyperlink DoubtHi ,
I have doubt regarding disabling Hyerlink in Datagrid. For some cases I don't want to show Hyperlink and some cases I want to show the Hyperlink Column. I don't want to hide the entire Column. -thanks Arun You will have to then hide the indvidual controls in the cell that you don't
want visible. A good place to do that is in the ItemDataBound event of the Grid, or you can build your own TemplateColumn. -Brock DevelopMentor http://staff.develop.com/ballen Show quoteHide quote > Hi , > > I have doubt regarding disabling Hyerlink in Datagrid. For some cases > I > don't want to show Hyperlink > and some cases I want to show the Hyperlink Column. I don't want to > hide the > entire Column. > -thanks > Arun 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:DataGrid 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:DataGrid> <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.)
DropDownList selectedIndexChanged event not firing
LinkButton Control Validator Control Change print orientation by website DataGrid SortCommand Event not fired on dynamically generated datagrid checkboxlist help Syntax for "NULL" in asp.net WebForm's Size DropDownList postback Format textbox to time format |
|||||||||||||||||||||||