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


E

Eric

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
 
Ad

Advertisements

B

bruce barker

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)
 
E

Eric

Thanks

bruce barker said:
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)
 
E

Eric

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
 
R

Riki

gv.ID

--

Riki
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
 
Ad

Advertisements

Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top