DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Mon, 13 Aug 2007 20:44:32 +0200,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    Ben ben@sdcsaz
          2    Teemu Keiski


how to reach linkbutton programmatically?   
Hi,

i try to reach in code-behind a linkbutton embedded into an ItemTemplate 
element of a gridview.
But i'm stuck ....

 <Columns>
<asp:TemplateField><ItemTemplate>
 <asp:LinkButton ID="lb1" runat="server"  OnClientClick="return 
confirm(Sure?');"
  CommandName="Delete" Text="go" >
  </asp:LinkButton>
</ItemTemplate></asp:TemplateField>
....

my code:
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
System.EventArgs) Handles Me.Load
            Dim tm As TemplateField
            Dim it As ITemplate
            Dim lk As LinkButton
            tm = GridView1.Columns.Item(0)
            it = tm.ItemTemplate
            lk=???

Thanks for help
Ben
Date:Mon, 13 Aug 2007 20:44:32 +0200   Author:  

Re: how to reach linkbutton programmatically?   
Hi,

see my blog post for background information

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/archive/2007/02/25/Understanding-the-naming-container-hierarchy-of-ASP.NET-databound-controls.aspx

Answer is that you need to loop through GridView's Rows, use FindControl 
against the row to locate the LinkButton. that is if you need to access them 
after they are (the grid is) being bound.

However if you need to do something like attach event handler to the 
LinkButton, you can (and you should) do it in RowCreated event of GridView 
which is raised for every row, when they are created (instantiated). And if 
you need to set something based o the data to which GridView is bound, you'd 
use RowDataBound event which also is raised for every row but only when 
GridView's DataBind is called.

-- 
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"Ben" <ben@sdcsaz> wrote in message 
news:eWEh8nd3HHA.1204@TK2MSFTNGP03.phx.gbl...

> Hi,
>
> i try to reach in code-behind a linkbutton embedded into an ItemTemplate 
> element of a gridview.
> But i'm stuck ....
>
> <Columns>
> <asp:TemplateField><ItemTemplate>
> <asp:LinkButton ID="lb1" runat="server"  OnClientClick="return 
> confirm(Sure?');"
>  CommandName="Delete" Text="go" >
>  </asp:LinkButton>
> </ItemTemplate></asp:TemplateField>
> ...
>
> my code:
> Protected Sub Page_Load(ByVal sender As Object, ByVal e As 
> System.EventArgs) Handles Me.Load
>            Dim tm As TemplateField
>            Dim it As ITemplate
>            Dim lk As LinkButton
>            tm = GridView1.Columns.Item(0)
>            it = tm.ItemTemplate
>            lk=???
>
> Thanks for help
> Ben
> 
Date:Mon, 13 Aug 2007 21:53:22 +0300   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us