473,320 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how to reach linkbutton programmatically?

Ben
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
Aug 13 '07 #1
3 6303
Hi,

see my blog post for background information

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-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@sdcsazwrote in message
news:eW**************@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

Aug 13 '07 #2
Ben
Thanks for replying

This is my attempt:

Dim lk As LinkButton
Dim gr As GridViewRow
For Each gr In GridView1.Columns
lk = CType(gr.FindControl("lb1"), LinkButton)
lk.Visible = False
Next

But i get: Unable to cast object of type
'System.Web.UI.WebControls.TemplateField' to type
'System.Web.UI.WebControls.GridViewRow'


"Teemu Keiski" <jo****@aspalliance.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,

see my blog post for background information

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-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@sdcsazwrote in message
news:eW**************@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


Aug 13 '07 #3
Ben
i found it:

For Each gr In GridView1.Rows



"Teemu Keiski" <jo****@aspalliance.comschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
Hi,

see my blog post for background information

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-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@sdcsazwrote in message
news:eW**************@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


Aug 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Eamon | last post by:
In the code-behind page I am building a table programmatically so that I can do some on-the-fly manipulation. I had found no way to use a datagrid with the solution I was seeking. is it possible to...
3
by: Rob Meade | last post by:
Hi all, I have a bit of code that programmatically adds some table cells/rows to a table. The last cell adds a LinkButton control, I call it like this: ...
7
by: Alex Maghen | last post by:
I have a DataGrid control with a LinkButton command column that deletes the row. What I want to do is set it up so that there's a client-side Confirm alert BEFORE the actual Delete command gets...
3
by: Gabe | last post by:
Hi there, The other day I tried to programmatically create an asp.net linkbutton during my Page_Load() event and attach a click event handler to the linkbutton, then add that linkbutton control...
0
by: OceanBreeze | last post by:
I have added a LinkButton to a table cell programmatically inside the Page_Load method. I also added a custom event to that link button. The same custom event is valid for all the link buttons. The...
2
by: Nathan Sokalski | last post by:
I am trying to create a FormView controls in which I access and modify the the controls in the PagerTemplate programmatically. However, I continue to recieve the following error: Object...
0
by: Scal | last post by:
Hello everyone; I try to create a web user control that has a Repeater (not that hard) to which I can add programmatically a new Repeater into ItemTemplate part. The point being to be able to...
3
by: Ben | last post by:
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"...
4
by: =?iso-8859-1?Q?Vicente_Garc=EDa?= | last post by:
Hi all, I have an GridView and when I put ALLOPAGIN = TRUE I can go to differents pages. The problem is that to do it they appear LinkButtons and I want to change then by Buttons. May anyone...
5
by: Peter Larsen [CPH] | last post by:
Hi, The following sample shows a LinkButton in the HeaderTemplate of a Repeater control. The problem is that i'm not able to access the linkbutton in code (in the cs file) as long as the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.