Prob w/ Datagrid

B

brock wade

I have a Datagrid with the following code:

<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("id") %>'
runat="server" OnClick="LinkButton1_Click">Details</
asp:LinkButton>Details</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

I'm getting this error message:
Compiler Error Message: BC30456: 'LinkButton1_Click' is not a member
of 'ASP.MainDepartment_aspx'.

Everything looks k in the design view.
What are some places I should think of looking? BTW I'm using .NET 1.1

Thanks!!!
 
N

Norm

I have a Datagrid with the following code:

<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("id") %>'
runat="server" OnClick="LinkButton1_Click">Details</
asp:LinkButton>Details</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

I'm getting this error message:
Compiler Error Message: BC30456: 'LinkButton1_Click' is not a member
of 'ASP.MainDepartment_aspx'.

Everything looks k in the design view.
What are some places I should think of looking? BTW I'm using .NET 1.1

Thanks!!!

Is there a 'LinkButton1_Click' member in the code-behind?
 
B

brock wade

Another item that may shed some light:

I have this to handle the button in my code-behind:

Private Sub LinkButton1_Click(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
Response.Redirect("Details.aspx?id=" & ID.ToString())
End Sub
 
N

Norm

Another item that may shed some light:

I have this to handle the button in my code-behind:

    Private Sub LinkButton1_Click(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs)
        Response.Redirect("Details.aspx?id=" & ID.ToString())
    End Sub

The LinkButton1 method has the wrong signature and you are not using
the correct event. Below is the corrected code:

Private Sub LinkButton1_Click(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.CommandEventArgs)
Response.Redirect("Details.aspx?id=" &
e.CommandArgument.ToString())
End Sub

<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%# Eval("id") %>'
runat="server" OnCommand="LinkButton1_Click">Details</
asp:LinkButton>Details</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>

There are 3 changes.
1: Instead of using OnClick, use OnCommand. Otherwise you dont get
easy access to the command argument.
2: Change the method signature to the one for the OnCommand event.
3: Change the method to get the id from the command argument instead
of ID. I have no idea where ID came from.

Note: I left the method name alone, but now its confusing. I would
change it to be something like ViewDetails. Something descriptive.
Hope this helps!
 
M

marss

Another item that may shed some light:

I have this to handle the button in my code-behind:

Private Sub LinkButton1_Click(ByVal source As Object, ByVal e As

Norm is right, the method has the wrong signature.
Just one addition to his suggestion:
You can't access private methods in the code-behind. They have to be
protected at least.

Mykola
http://marss.co.ua
 
W

wade.brock

Thanks Norm,
I rtied the changes and still get the Compiler Error Message: BC30456:
'LinkButton1_Click' is not a member
of 'ASP.MainDepartment_aspx'.

Also I think I have my html in the wron order too... do you see any
problems? It is re-underlining <form, <asp:datagrid, and <columns>

<BODY>
<div>
<div>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="dgEmployees" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandArgument='<%#
Eval("id") %&>'
runat="server" OnCommand="LinkButton1_Click">Details</

asp:LinkButton>Details</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
</form>
<div>
<asp:label id="Label4" runat="server" Width="253px">Type desired
Excel Spreadsheet name without the .xls extension:</asp:label>
<asp:textbox id="txtFileName" Runat="server"></asp:textbox>
<asp:button id="Button1" onclick="doExport" runat="server"
Width="123px" Text="Export to Excel"></asp:button>
</div>
</div>
<asp:label id="EmpNum" " runat="server"></asp:label><asp:label
id="Label1" runat="server">First Name</asp:label>
<asp:label id="Label2" runat="server" >Last Name</asp:label></FORM></
FORM>
<DIV></DIV>
<DIV></DIV>
</div>
</BODY>
 
W

wade.brock

Disregard my last post about my html being in the wrong order... I
simply had an extra "Details</asp:LinkButton>" in the block....

But I'm still getting this error message:

Compiler Error Message: BC30456: 'LinkButton1_Click' is not a member
of 'ASP.MainDepartment_aspx'.
 
N

Norm

Disregard my last post about my html being in the wrong order... I
simply had an extra "Details</asp:LinkButton>" in the block....

But I'm still getting this error message:

Compiler Error Message: BC30456: 'LinkButton1_Click' is not a member
of 'ASP.MainDepartment_aspx'.




- Show quoted text -

Thanks Marss I didn't notice that. Wade, read Marss post above. The
reason that it is still throwing the error is becase it can't see it.
Change "Private" to "Protected" or "Public".
 
W

wade.brock

Yeah I thought that might have been it from other similar BC30456 "is
not a member" posts, but changing to either Public or Protected did
not work.
 
N

Norm

Yeah I thought that might have been it from other similar BC30456 "is
not a member" posts, but changing to either Public or Protected did
not work.

Well, I don't know what else to say other than post the full source of
this page. There must be something else going wrong.
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top