|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to react to an ImageButon in a DataList ?Hi,
I'm used to LinkButtons with CommandName property (Update, Delete, etc.) in a DataList to get the correspondind events, but it does'nt work with an ImageButton. The PostBack seems to appen, but the event handler is not called. So i'm sure it's possible to use other kind of butons than LinkButon, typically an ImageButton, but i don't understand why it does'nt works ? Thanks and best regards GL *** Sent via Developersdex http://www.developersdex.com *** Hi -
I believe that in order to capture control events when they are templated items you have to create the event handler for the "ItemCommand" for the DataList. After creating the event handler in the code behind, I edited the page in HTML and added the following CommandName and CommandArgument for the image button. I bound the orderId from the Northwind database orders table so that when the button is clicked the command argument is actually the orderId. <asp:datalist id=DataList1 style="Z-INDEX: 101; LEFT: 112px; POSITION: absolute; TOP: 40px" runat="server" DataMember="Orders" DataKeyField="OrderID" DataSource="<%# dataSet11 %>"> <ItemTemplate><asp:ImageButton id="ImageButton1" runat="server" ImageUrl="..." CommandName="transfer" CommandArgument='<%# DataBinder.Eval(Container, "DataItem.orderid") %>'></asp:ImageButton> </ItemTemplate> </asp:datalist> In the code behind I handled the click like this: private void DataList1_ItemCommand(object source, System.Web.UI.WebControls.DataListCommandEventArgs e) { // sling takes the orderId, and it can be used for whatever... string sling = e.CommandArgument.ToString(); Server.Transfer("aPage.aspx"); } The same applies to DataGrids as well...and perhaps some other controls as well... HTH, and good luck! EJD Everthing is OK with a LinkButton, but nothing to do with an
ImageButton. So, i've found a solution with an simple image inside à LinkButton and it works ! <asp:LinkButton id="Linkbutton2" runat="server" Width="50px" CommandName="Delete"> <IMG alt="" src="images/btn_delete.gif" border="0"></asp:LinkButton> Thanks ;-) Gilles *** Sent via Developersdex http://www.developersdex.com *** Oh, and another thing. I've noticed that from time to time after
modifying a DataGrid or DataList that sometimes that events that you had created for the control using the designer or whatever just seem to stop working. As in the code is still there in the code behind, but the event handler has lost its link to the control. I don't know if that applies here... EJD
Can we have more than 1 'control to validate' for a single validat
Detailsview empty dataset insert search criteria web forms textbox sizing issues in Firefox Newbie to web side - prompt the user..... DataGrid help on Datagrid's SelectedIndexChanged event How to use Tab controls About Page FAQ software bind a Checkboxlist with a string ? |
|||||||||||||||||||||||