views:

33

answers:

3

Hi,

I am using a datalist inside which I have defined an itemtemplate. I am using asp:LinkButton inside this itemtemplate. I have used an OnClick="methodname" in this linkbutton tag. I have the corresponding mehtodname defined in my code behind, However I keep getting a Java runtime error when the page loads up and when I click on any of the items in the datalist. It says that I have not javascript function function defined with the name mentioned.

Isnt asp:LinkButton a server control. I want to use my c# code behind and not javascript. How do I proceed??

<asp:DataList ID="DLID" RepeatColumns="5" RepeatDirection="Horizontal" runat="server">

<ItemTemplate>
<div class="home">
<div class="homeblock"></div>
<div class="homeitem">
<ul><li><span style="font-size:small;">
<asp:LinkButton ID="TopItem" runat="server" OnClick="Item_OnClick"><%# Container.DataItem %></asp:LinkButton>
</span></li></ul>
</div>
</div>
</ItemTemplate>
</asp:DataList>

A: 

Hi,

As you have not supplied any code,

Take a look at this site it might help you:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemtemplate.aspx Details how to use a listview template the example includes a link button.

PS. did you use the runat="server" statement?

Be happy and enjoy life

Julian
yes I do have the runat server for both datalist and linkbutton tags. Please see my update question. Thanks
VP
A: 

Just put the C# code/logic in the asp:LinkButton Click Event.

Emad Mokhtar
A: 

Works perfectly fine for me. Used your markup code minus the class names. Here is the code-behind I used:

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        string[] ds = new string[] { "a", "b", "c", "d", "e", "f", "g" };
        DLID.DataSource = ds;
        DLID.DataBind();
    }
}

protected void Item_OnClick(object sender, EventArgs e)
{
    //do stuff
}

What is the exact error message?

JumpingJezza
this works now. Thanks for the simplified code! Also I need to bind a string to an asp:label control. I need to actually to bind it to the string that is selected by user from the "TopItem" linkbutton control. How can I do this? `<asp:Label ID="Item" runat="server" Text="<%# Container.DataItem %>"`>`</asp:Label`> Can I bind this asp:label control to a string? Or do i have to use a diferent control to achieve this?
VP
I just solved this in my code behind by setting the label's text property to my string value that I extract in the onclick event. Thanks anyways!
VP