Results 1 to 4 of 4

Thread: [Resolved] OnEditCommand Not Firing in DataList

  1. #1

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551

    [Resolved] OnEditCommand Not Firing in DataList

    Hello,

    I had a page that I coded in Dreamweaver, before i was convinced to start using VS.NET IDE... Well, I had a DataList that had a button in the itemtemplate. every time the button was clicked, i had the EditCommand Event fire for the Datalist, and from there did what i needed to do..

    Now i'm converting this page to using codebehind, and i'm using VisualStudio.NET to code in. I can't seem to get the EditCommand Event to fire for the life of me.

    Here is my HTML for the DataList:

    VB Code:
    1. <table width="500" align="center" border="0" cellpadding="0" cellspacing="0">
    2.     <asp:DataList HeaderStyle-HorizontalAlign="center" id="dlZipCodes" runat="server" Width="500" Height="80">
    3.         <HeaderTemplate>
    4.             <tr>
    5.                 <td><strong><font size="2" face="Verdana">Expires:</font></strong><font size="2" face="Verdana">&nbsp;</font></td>
    6.                 <td><font size="2" face="Verdana"><strong>Visible:</strong></font></td>
    7.                 <td><font size="2" face="Verdana"><strong>Zip Code:</strong></font></td>
    8.                 <td>&nbsp;</td>
    9.             </tr>
    10.         </HeaderTemplate>
    11.         <ItemTemplate>
    12.             <tr>
    13.                 <td><%# Convert.ToDateTime(Container.DataItem("Expires")).ToShortDateString %></td>
    14.                 <td>
    15.                     <asp:CheckBox ID="chkZIP_Visible" Runat="server" Text="" Checked='<%# Container.DataItem("Visible") %>' />
    16.                 </td>
    17.                 <td>
    18.                     <asp:DropDownList Runat="server" ID="lstZipCodes"></asp:DropDownList>
    19.                 </td>
    20.                 <td>
    21.                     <asp:Button CommandName="edit" Runat="server" Text="Update" />
    22.                     <asp:Label Runat="server" ID="lblZIP_ID" Visible="True" Text='<%# Container.DataItem("ID") %>' />
    23.                     <asp:Label Runat="server" ID="lblZIP_Zip" Visible="True" text='<%# Container.DataItem("ZipCode") %>' />
    24.                 </td>
    25.             </tr>
    26.         </ItemTemplate>
    27.     </asp:DataList>
    28. </table>



    Here's the Event Code in my CodeBehind:
    VB Code:
    1. Private Sub dlZipCodes_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataListCommandEventArgs) Handles dlZipCodes.EditCommand
    2.  
    3.           'My Code Here
    4.            Dim objFile As System.IO.TextWriter
    5.            objFile = IO.File.CreateText("F:\Out.txt")
    6.            objFile.WriteLine("UPDATE ZipCodes SET ZipCode = '" & strZip & "', Visible = " & intVisible & " WHERE ID = " & intID)
    7.            objFile.Close()
    8.  
    9. End Sub

    I can't figure out what is going wrong.. the event never fires (i've stuck in some code in the sub that writes to a textfile, but the text file remains empty to no avail :/..

    Anyways, i'm sure there's something small that i'm missing, i just can't figure out what... thanks for the help guys!
    Last edited by Redth; Jan 4th, 2003 at 11:14 AM.

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    You are missing the page directives for the .aspx file. The directives tell the name and locaction of the code-behind file, as well as other information.

  3. #3

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    nope, that's not the problem...

    All the other subs in the code-behind file work just fine... i know for sure that the right code-behind file is being targetted...

    any other ideas?

  4. #4

    Thread Starter
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    Well,

    After About 3 Hours, i finally got it working... There was something tricky going on to do with PostBacks. Apparently the Event that wasn't fired fires on the postback (i did not know this), and so since i had some code to populate that datagrid that was firing every page load, the EditCommand event was not firing...

    Solution: I simply moved that code that was binding the datalist on every page load so that it fired only on Non-PostBacks...

    Works now! Phew!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width