Results 1 to 5 of 5

Thread: cant pass that item

  1. #1

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492

    cant pass that item

    Ive got an image button on a grid...

    then i have this code:

    Code:
        Private Sub dgActionItems_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgActionItems.ItemCommand
            ' Check to see if the user selected the pager. If not, then this must be
            ' a command button
            If (e.Item.ItemType <> ListItemType.Pager) Then
    
                Select Case e.CommandName
                    Case "Edit"
                        'edit action item
                    Case "Delete"
                        'delete the action item
                        Dim f As New Functions
                        f.DeleteActionItem(CType(e.Item.Cells(0).Text, Long))
                    Case "Task"
                        'send the task here
                End Select
            Else
                ' This section would be where any page control stuff goes
            End If
        End Sub
    The CType(e.Item.Cells(0).Text) never gets the value ... it always errors out saying cannot convert "" to type integer...If I change and debug it to e.Item.Cells(4).Text I see the other field which is a date...

    But whenever I try e.Item.Cells(0).Text or e.Item.Cells(1).Text the debug shows "" even though in reality these are numbers. My grid shows the number when I view it but in debug no luck...

    All Im trying to do is delete a record...

    I cant even get it to pass that ID number to the function:

    Code:
      Public Function DeleteActionItem(ByVal lngID As Long)
    
            Dim conMyData As SqlConnection
            Dim cmdDelete As SqlCommand
    
            Try
                conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn"))
                cmdDelete = New SqlCommand("delete_action_item_by_action_item_id", conMyData)
    
                With cmdDelete
                    .CommandType = CommandType.StoredProcedure
                    'add the parameters
                    .Parameters.Add("@ActionItemID", SqlDbType.BigInt).Value = lngID
                    conMyData.Open()    'open a connection
                    .ExecuteNonQuery()  'execute it
                End With
    
            Catch ex As Exception
                Response.Write("An Error Occurred: " & ex.ToString())
                'clean up and close resources
            Finally
                cmdDelete = Nothing
                conMyData.Close()
                conMyData = Nothing
            End Try
        End Function
    The code to delete should be fine (fairly simple). But I cannot seem to pass that ID number from the grid.

    Any help is appreciated.

    Thanks,
    Jon

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Post the html of the grid (not after it was ran, but the actual grid markup in the designer).

  3. #3

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    HTML of the grid:

    VB Code:
    1. <asp:datagrid id="dgActionItems" Runat="server" Width="100%" AutoGenerateColumns="False" ItemStyle-Font-Size="10"
    2.                                         ItemStyle-Font-Name="arial" AllowSorting="True">
    3.                                         <ItemStyle Font-Size="10pt" Font-Names="arial"></ItemStyle>
    4.                                         <HeaderStyle Font-Size="10pt" Font-Names="Arial" BackColor="#DCE3EB" horizontalalign="center"></HeaderStyle>
    5.                                         <Columns>
    6.                                             <asp:TemplateColumn Visible="False" HeaderText="Action Details">
    7.                                                 <ItemTemplate>
    8.                                                     <%# DataBinder.Eval(Container.DataItem, "actionitemid") %>
    9.                                                 </ItemTemplate>
    10.                                             </asp:TemplateColumn>
    11.                                             <asp:TemplateColumn SortExpression="1" HeaderText="#">
    12.                                                 <ItemStyle Width="2%"></ItemStyle>
    13.                                                 <ItemTemplate>
    14.                                                     <%# DataBinder.Eval(Container.DataItem, "actionitemnumber") %>
    15.                                                 </ItemTemplate>
    16.                                             </asp:TemplateColumn>
    17.                                             <asp:TemplateColumn SortExpression="2" HeaderText="Priority">
    18.                                                 <ItemStyle Width="5%"></ItemStyle>
    19.                                                 <ItemTemplate>
    20.                                                     <%# DataBinder.Eval(Container.DataItem, "priorityid") %>
    21.                                                 </ItemTemplate>
    22.                                             </asp:TemplateColumn>
    23.                                             <asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="opendate" SortExpression="3" HeaderText="Open"
    24.                                                 DataFormatString="{0:dd-MMM-yyyy}">
    25.                                                 <ItemStyle Width="10%"></ItemStyle>
    26.                                             </asp:BoundColumn>
    27.                                             <asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="targetdate" SortExpression="4" HeaderText="Target"
    28.                                                 DataFormatString="{0:dd-MMM-yyyy}">
    29.                                                 <ItemStyle Width="10%"></ItemStyle>
    30.                                             </asp:BoundColumn>
    31.                                             <asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="closeddate" SortExpression="5" HeaderText="Closed"
    32.                                                 DataFormatString="{0:dd-MMM-yyyy}">
    33.                                                 <ItemStyle Width="10%"></ItemStyle>
    34.                                             </asp:BoundColumn>
    35.                                             <asp:TemplateColumn SortExpression="6" HeaderText="Responsible">
    36.                                                 <ItemStyle Width="5%"></ItemStyle>
    37.                                                 <ItemTemplate>
    38.                                                     <%# DataBinder.Eval(Container.DataItem, "Responsibleperson") %>
    39.                                                 </ItemTemplate>
    40.                                             </asp:TemplateColumn>
    41.                                             <asp:TemplateColumn SortExpression="7" HeaderText="Action Item Type">
    42.                                                 <ItemStyle Width="15%"></ItemStyle>
    43.                                                 <ItemTemplate>
    44.                                                     <%# DataBinder.Eval(Container.DataItem, "actionitemtype") %>
    45.                                                 </ItemTemplate>
    46.                                             </asp:TemplateColumn>
    47.                                             <asp:TemplateColumn HeaderText="Action Item">
    48.                                                 <ItemStyle Width="35%"></ItemStyle>
    49.                                                 <ItemTemplate>
    50.                                                     <%# DataBinder.Eval(Container.DataItem, "actionitem") %>
    51.                                                 </ItemTemplate>
    52.                                             </asp:TemplateColumn>
    53.                                             <asp:ButtonColumn CommandName="Edit" ButtonType="LinkButton" Text="<img src=images\edit.gif border=0 alt='Edit Action Item'>"
    54.                                                 ItemStyle-HorizontalAlign="Center">
    55.                                                 <ItemStyle></ItemStyle>
    56.                                             </asp:ButtonColumn>
    57.                                             <asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton" Text="<img src=images\delete.gif border=0 alt='Delete Action Item'>"
    58.                                                 ItemStyle-HorizontalAlign="Center">
    59.                                                 <ItemStyle></ItemStyle>
    60.                                             </asp:ButtonColumn>
    61.                                             <asp:ButtonColumn CommandName="SendTask" ButtonType="LinkButton" Text="<img src=images\sendtask.gif border=0 alt='Send Action Item'>"
    62.                                                 ItemStyle-HorizontalAlign="Center">
    63.                                                 <ItemStyle></ItemStyle>
    64.                                             </asp:ButtonColumn>
    65.                                         </Columns>
    66.                                     </asp:datagrid>

  4. #4

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    anyone ?

  5. #5

    Thread Starter
    Banned jhermiz's Avatar
    Join Date
    Jun 2002
    Location
    Antarctica
    Posts
    2,492
    got it...
    used a boundcolumn for index 0
    instead of a template column.

    works :-d

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