473,748 Members | 10,889 Online
Bytes | Software Development & Data Engineering Community
+ 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="S qlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" DataSourceID="S qlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArg s)
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 6082
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="S qlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server" DataSourceID="S qlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArg s)
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******** ********@TK2MSF TNGP02.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:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID=" SqlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArg s)
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.EventArg s)
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.W ebControls.Grid View
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam. comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.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:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID=" SqlDataSource1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As System.EventArg s)
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.EventArg s) 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.W ebControls.Grid View
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam. comschreef in bericht
news:%2******** ********@TK2MSF TNGP02.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:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID= "SqlDataSource1 " >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As
System.EventA rgs) 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******** ******@TK2MSFTN GP03.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.EventArg s) 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.W ebControls.Grid View
what i want is the ID of the gridview.
Thanks
"bruce barker" <no****@nospam. comschreef in bericht
news:%2******* *********@TK2MS FTNGP02.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 ="SqlDataSource 1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n1" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

<asp:GridView ID="GridView2" runat="server"
DataSourceID ="SqlDataSource 1" >
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:LinkButt on ID="lb1" OnClick="go" runat="server"
Text="go">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="n2" ReadOnly="True"/>
</asp:BoundField>
</Columns>
</asp:GridView>

Protected Sub go(ByVal sender As Object, ByVal e As
System.Event Args) 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
5590
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 the "DataTextField" as the productID of the product that I want to add. This works but the button displays the productID as the text instead of "Add to Cart". What is the best way to get this to work?
3
2217
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 pnlLinks.Controls.Add(lnkBut) Next
0
1747
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 easily reproduced and it seems like a major .NET flaw/limitation that I was hoping you could explain to me as it is really frustrating me. I just want to be able to get info for a row clicked, whether it is a Repeater, GridView, etc. I have...
0
4927
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 row. I tried using the following to grab the index, which appears to work on command columns, but not with buttons in a template? is this true? or am i missing something. how do I get the row index? Its returning the ID of the record, not the index...
2
4748
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 kind person would like me to email this link too I can do... My Grid View consists of 4 cols:- 1 - ItemTemplate (checkbox) 2 - imageField 3 - ItemTemplate (linkbutton) 4 - ImageField The data that Im binding too consist of nearly 1000...
1
1332
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 have a linkbutton (a templatefield) each. When this linkbutton is clicked, I have some events to be performed. My scenario: 1. I place the user control in a web page and run. It shows the Gridview1 by default. 2. I click the tab2 which shows...
2
5484
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
11900
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 retrieved and showed in this GridView produce more than one page of data. A given user clicks on the first row hyper link on the Grid on the first page, then the first row hyper link color changes to look as "visited". Then the user navigates to...
0
2705
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 row. I would like to display the footer row, only when a LinkButton "Add New" is clicked. And after the new record is saved to the database, let the footer row disappear. In the LinkButton's click event handler, I simply say:
0
9541
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9321
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9247
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8242
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6074
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3312
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2782
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.