Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Datagrid Hyperlink Doubt

Reply
Thread Tools

Datagrid Hyperlink Doubt

 
 
Arun
Guest
Posts: n/a
 
      05-07-2005
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


 
Reply With Quote
 
 
 
 
Brock Allen
Guest
Posts: n/a
 
      05-07-2005
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



> 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




 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-08-2005
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">
<aspataGrid 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>
</aspataGrid>
<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.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
dotnet doubt can any body clarify my doubt challa462@gmail.com ASP .Net 0 08-22-2012 06:02 AM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink davetichenor ASP .Net 1 10-30-2006 02:57 PM
How to add a hyperlink column to asp.net datagrid - where only one value is a hyperlink Dave ASP .Net Datagrid Control 0 10-21-2006 07:48 PM
doubt about doubt Bob Nelson C Programming 11 07-30-2006 08:17 PM
Dynamically Hyperlink and Event Handler for the Hyperlink ? Ken ASP .Net Datagrid Control 1 08-15-2003 11:38 PM



Advertisments