473,473 Members | 1,755 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

how to get the name of the gridview where the linkbutton has been clicked?

Hi,

there are several gridviews all with a linkbutton which all trigger the same
procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArgs)
dim gv as string
'need to get into a variable the name of the gridview where the linkbutton
has been clicked
End Sub
Oct 25 '08 #1
5 6057
pretty simple

// find my parent gridview

GridView gv = null;
for (var ctl = sender as Control; ctl != null; ctl = ctl.Parent)
{
if (ctl is GridView)
{
gv = ctl as GridView;
break;
}
}
-- bruce (sqlwork.com)

Eric wrote:
Hi,

there are several gridviews all with a linkbutton which all trigger the same
procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArgs)
dim gv as string
'need to get into a variable the name of the gridview where the linkbutton
has been clicked
End Sub

Oct 25 '08 #2
Thanks

"bruce barker" <no****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
pretty simple

// find my parent gridview

GridView gv = null;
for (var ctl = sender as Control; ctl != null; ctl = ctl.Parent)
{
if (ctl is GridView)
{
gv = ctl as GridView;
break;
}
}
-- bruce (sqlwork.com)

Eric wrote:
>Hi,

there are several gridviews all with a linkbutton which all trigger the
same procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArgs)
dim gv as string
'need to get into a variable the name of the gridview where the
linkbutton has been clicked
End Sub

Oct 26 '08 #3
I was a little too fast ...

i converted into vb.net:

Protected Sub bekijk(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gv As GridView = Nothing
Dim ctl As Object = TryCast(sender, Control)
While ctl IsNot Nothing
If TypeOf ctl Is GridView Then
gv = TryCast(ctl, GridView)
Exit While
End If
ctl = ctl.Parent
End While

but this gives this: System.Web.UI.WebControls.GridView
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
pretty simple

// find my parent gridview

GridView gv = null;
for (var ctl = sender as Control; ctl != null; ctl = ctl.Parent)
{
if (ctl is GridView)
{
gv = ctl as GridView;
break;
}
}
-- bruce (sqlwork.com)

Eric wrote:
>Hi,

there are several gridviews all with a linkbutton which all trigger the
same procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArgs)
dim gv as string
'need to get into a variable the name of the gridview where the
linkbutton has been clicked
End Sub

Oct 26 '08 #4
gv.ID

--

Riki

Eric wrote:
I was a little too fast ...

i converted into vb.net:

Protected Sub bekijk(ByVal sender As Object, ByVal e As
System.EventArgs) Dim gv As GridView = Nothing
Dim ctl As Object = TryCast(sender, Control)
While ctl IsNot Nothing
If TypeOf ctl Is GridView Then
gv = TryCast(ctl, GridView)
Exit While
End If
ctl = ctl.Parent
End While

but this gives this: System.Web.UI.WebControls.GridView
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>pretty simple

// find my parent gridview

GridView gv = null;
for (var ctl = sender as Control; ctl != null; ctl =
ctl.Parent) {
if (ctl is GridView)
{
gv = ctl as GridView;
break;
}
}
-- bruce (sqlwork.com)

Eric wrote:
>>Hi,

there are several gridviews all with a linkbutton which all trigger
the same procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As
System.EventArgs) dim gv as string
'need to get into a variable the name of the gridview where the
linkbutton has been clicked
End Sub

Oct 26 '08 #5
Thanks

"Riki" <ri**@dontnagme.comschreef in bericht
news:uz**************@TK2MSFTNGP03.phx.gbl...
gv.ID

--

Riki

Eric wrote:
>I was a little too fast ...

i converted into vb.net:

Protected Sub bekijk(ByVal sender As Object, ByVal e As
System.EventArgs) Dim gv As GridView = Nothing
Dim ctl As Object = TryCast(sender, Control)
While ctl IsNot Nothing
If TypeOf ctl Is GridView Then
gv = TryCast(ctl, GridView)
Exit While
End If
ctl = ctl.Parent
End While

but this gives this: System.Web.UI.WebControls.GridView
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>pretty simple

// find my parent gridview

GridView gv = null;
for (var ctl = sender as Control; ctl != null; ctl =
ctl.Parent) {
if (ctl is GridView)
{
gv = ctl as GridView;
break;
}
}
-- bruce (sqlwork.com)

Eric wrote:
Hi,

there are several gridviews all with a linkbutton which all trigger
the same procedure.
I need to know from which gridview the linkbutton has been clicked.

Thanks
Eric
Here the code:

<asp:GridView ID="GridView1" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID="SqlDataSource1" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As
System.EventArgs) dim gv as string
'need to get into a variable the name of the gridview where the
linkbutton has been clicked
End Sub


Oct 26 '08 #6

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

Similar topics

3
by: | last post by:
Hello, I am trying to get add a product to a cart from a gridview control when a button in the gridview is clicked. I have a book on how to do this in asp.net 2.0 but it is done by specifying...
3
by: rn5a | last post by:
Consider the following code which creates LinkButtons dynamically: For i = 1 to 5 lnkBut = New LinkButton lnkBut.ID = "lnkBut" & i lnkBut.Text = i.ToString & " " lnkBut.CommandName = i...
0
by: =?Utf-8?B?cGI2NDgxNzQ=?= | last post by:
We have been having this problem for months and always assumed it was because of our somewhat complicated setup. I have just spent almost all of today making this into a simple example that can be...
0
by: David Lozzi | last post by:
Howdy, I have a gridview with a linkbutton in a template column (code is below). When the linkbutton is clicked i want to display a little confirm right in the gridview to confirm deleting the...
2
by: dixonjm | last post by:
I have quite a complicated problem with the above. I will do my best to explain, although I have a word doc (too large to attach here 149KB) with the problem explained full with screen shots if any...
1
by: akjal | last post by:
Hi all, I have one user control with 2 gridview and 2 tabs(created using javascript).When tab1 clicks Gridview1 will b shown(this is the default) and tab2 click shows Gridview2. These 2 gridviews...
2
by: Dinu | last post by:
Hi how to get text of a control in itemtemplate of gridview and how can we access and set it properties dynamycally?? Thanks
4
by: Jeff | last post by:
Hi, I have a ASP.NET 2.0 Web Application. Many of the pages use the ASP.NET GridView with paging and sorting. One of the columns of this Gridview is a template column (LinkButton). The data being...
0
by: gnewsgroup | last post by:
Well, I am trying to use the footer row of a GridView for insertion purpose. There are some articles about this, for example, the gridviewguy.com has an example, which always displays the footer...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.