Results 1 to 7 of 7

Thread: delete record from datagrid [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075

    delete record from datagrid [RESOLVED]

    I'm trying to delete a record from a datagrid, but can't seem to get my "Delete Command EventHandler" to fire. I have a datagrid with a delete button. Here's my code:


    Sub deleteRecord(sender as Object, e as DataGridCommandEventArgs)
    lblVerify.Text = "Record has been Deleted"
    End Sub

    <asp:datagrid id=DataGrid1 onDeleteCommand="deleteRecord" >
    <asp:ButtonColumn CommandName="Delete">


    when I click the delete button it never makes it to my "deleteRecord" procedure. Any suggestions?

    thanks,
    eye
    Last edited by EyeTalion; Nov 5th, 2002 at 01:43 PM.

  2. #2
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    I had a very similar problem a while ago. I actually gave and tried a different solution. Then I decided to try the datagrid command button solution again and this time it worked and I was certain I had exactly the same code the first time around but who knows

    The only thing that comes to mind in your case is you have no check in your code to see if it was the Delete command that was fired.

  3. #3

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    it's not being fired. If it was I'd make it to my lblVerify.Text = "Record has been Deleted".

  4. #4

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    here's the actual code:

    Sub deleteRecord(sender as Object, e as DataGridCommandEventArgs)
    lblVerify.Text = "Record has been Deleted"
    End Sub


    <asp:datagrid id=DataGrid1 onDeleteCommand="deleteRecord" style="Z-INDEX: 107; LEFT: 25px; POSITION: absolute; TOP: 203px" runat="server" Height="244px" Width="724px" Font-Names="Courier New" DataSource="<%# DataSet11 %>" DataMember="PBSS_BID" AutoGenerateColumns="False">
    <AlternatingItemStyle ForeColor="Black" BackColor="Ivory"></AlternatingItemStyle>
    <HeaderStyle Font-Bold="True" ForeColor="Black" BackColor="LightGray"></HeaderStyle>
    <Columns>
    <asp:BoundColumn DataField="BID_ID" SortExpression="BID_ID" HeaderText="BID ID"></asp:BoundColumn>
    <asp:BoundColumn DataField="BID_TYPE_CODE" SortExpression="BID_TYPE_CODE" HeaderText="BID TYPE"></asp:BoundColumn>
    <asp:BoundColumn DataField="BID_SCHEDULE_DESC" SortExpression="BID_SCHEDULE_DESC" HeaderText="DESCRPITION"></asp:BoundColumn>
    <asp:BoundColumn DataField="BUYER_NAME" SortExpression="BUYER_NAME" HeaderText="BUYER"></asp:BoundColumn>
    <asp:ButtonColumn Text="Delete" ButtonType="PushButton" HeaderText="DELETE" CommandName="Delete"></asp:ButtonColumn>
    </Columns>
    </asp:datagrid>

  5. #5
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Try setting enableviewstate=false for the datagrid.

  6. #6

    Thread Starter
    Frenzied Member EyeTalion's Avatar
    Join Date
    Jul 2000
    Location
    New York
    Posts
    1,075
    musican you ROCK!! I've been banging my head for days now trying to figure this out....thanks, eye

    what is the "EnableViewState" function?

  7. #7
    Hyperactive Member
    Join Date
    Dec 2001
    Location
    Dublin, Ireland
    Posts
    262
    Enableviewstate saves the contents of the control to a hidden field in the generated form and is retained between posts so as to refill the control. When you post back a form with a textbox for example you should see what you typed into the textbox still there unless you set enableviewstate=false. It's important to set it to false for events to work properly in datagrids.
    It's also important to set it to false when you know the control will be filled by a procedure because then it's uneccessary to save the data between pages and setting it to false reduces the amount of data in the hidden field and means the page will appear to the user quicker, especially if it's a datagrid with alot of items in it.

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