Using Button In Datalist?

  • Thread starter Patrick Olurotimi Ige
  • Start date
P

Patrick Olurotimi Ige

Can i have a Button in a Datalist?
The button is for posting a form to the the Database
FOr example:-
<ASP:DataList id="heading0" RepeatLayout="Flow"
RepeatDirection="Horizontal" runat="server">
<ItemTemplate>
<asp:button id="cmdSubmit1" class="button"
text=<%#DataBinder.Eval(Container.DataItem, "headerDescription") %>
OnClick="formUpdate" runat="server"/>
</itemTemplate>
</asp:datalist>
But its not firing?
Any ideas?
 
B

Brock Allen

Yes you can use a Button in a DataList and handle events as you've decribed.
I'm not quite sure why your code snippet isn't working (I don't know what
the codebehind looks like). Another idea for handling events on the Button
in the DataList is to handle the DataList's ItemCommand event. With ItemCommand,
the DataListCommandEventArgs tells you which item in the DataList contained
the button.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 
P

Patrick Olurotimi Ige

Thx Brock for the reply..
The code is below
What am i missing?

-------------------------------
Sub FormUpDate(ByVal sender As Object, ByVal e As
DataListCommandEventArgs) Handles DataList1.ItemCommand

If e.CommandName = "UpDate" Then
Response.Write("test")

End If

End Sub

<asp:DataList Runat="server" EnableViewState="True" ID="DataList1"
OnItemCommand="FormUpDate">
<ItemTemplate>

<asp:Button id="cmdSubmit" text="Save" runat="server"
CommandName="UpDate"/>
</ItemTemplate>
</asp:DataList>
 
B

Brock Allen

That code below looks fine except you have the event wired up twice. You
only need one of the Handles keyword in the VB.NET code or the OnItemCommand
in the ASPX code. Having both will cause the event to be fired twice.

As for the reason the event isn't firing, are you databinding upon every
postback in Page_Load? You should only DataBind when IsPostBack = false,
or, IOW, the first access to the page.

-Brock
DevelopMentor
http://staff.develop.com/ballen
 

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