Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 ASP.NET
 cell not getting value

Author  Topic 

jhermiz

3564 Posts

Posted - 2004-10-11 : 17:59:36
Ive got an image button on a grid...

then i have this 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:


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

chadmat
The Chadinator

1974 Posts

Posted - 2004-10-11 : 18:43:07
Where are you binding data to the grid?

-Chad

http://www.clrsoft.com

Software built for the Common Language Runtime.
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-10-12 : 08:27:22
Where ?

In the page load event...I see the data there
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-10-12 : 08:29:54
HTML for the grid:


<asp:datagrid id="dgActionItems" Runat="server" Width="100%" AutoGenerateColumns="False" ItemStyle-Font-Size="10"
ItemStyle-Font-Name="arial" AllowSorting="True">
<ItemStyle Font-Size="10pt" Font-Names="arial"></ItemStyle>
<HeaderStyle Font-Size="10pt" Font-Names="Arial" BackColor="#DCE3EB" horizontalalign="center"></HeaderStyle>
<Columns>
<asp:TemplateColumn Visible="False" HeaderText="Action Details">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "actionitemid") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="1" HeaderText="#">
<ItemStyle Width="2%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "actionitemnumber") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="2" HeaderText="Priority">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "priorityid") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="opendate" SortExpression="3" HeaderText="Open"
DataFormatString="{0:dd-MMM-yyyy}">
<ItemStyle Width="10%"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="targetdate" SortExpression="4" HeaderText="Target"
DataFormatString="{0:dd-MMM-yyyy}">
<ItemStyle Width="10%"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn ItemStyle-HorizontalAlign="Center" DataField="closeddate" SortExpression="5" HeaderText="Closed"
DataFormatString="{0:dd-MMM-yyyy}">
<ItemStyle Width="10%"></ItemStyle>
</asp:BoundColumn>
<asp:TemplateColumn SortExpression="6" HeaderText="Responsible">
<ItemStyle Width="5%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "Responsibleperson") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn SortExpression="7" HeaderText="Action Item Type">
<ItemStyle Width="15%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "actionitemtype") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="Action Item">
<ItemStyle Width="35%"></ItemStyle>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "actionitem") %>
</ItemTemplate>
</asp:TemplateColumn>
<asp:ButtonColumn CommandName="Edit" ButtonType="LinkButton" Text="<img src=images\edit.gif border=0 alt='Edit Action Item'>"
ItemStyle-HorizontalAlign="Center">
<ItemStyle></ItemStyle>
</asp:ButtonColumn>
<asp:ButtonColumn CommandName="Delete" ButtonType="LinkButton" Text="<img src=images\delete.gif border=0 alt='Delete Action Item'>"
ItemStyle-HorizontalAlign="Center">
<ItemStyle></ItemStyle>
</asp:ButtonColumn>
<asp:ButtonColumn CommandName="SendTask" ButtonType="LinkButton" Text="<img src=images\sendtask.gif border=0 alt='Send Action Item'>"
ItemStyle-HorizontalAlign="Center">
<ItemStyle></ItemStyle>
</asp:ButtonColumn>
</Columns>
</asp:datagrid>
Go to Top of Page

chadmat
The Chadinator

1974 Posts

Posted - 2004-10-12 : 12:44:03
Hmmmm... Data should be there then. I was thinking maybe you weren't binding until after page_load.

You might try adding an onclicked="myHandler" to that button?

instead of handling in the ItemCommand event.

-Chad
Go to Top of Page

jhermiz

3564 Posts

Posted - 2004-10-12 : 12:46:38
I got it dont worry thanks though Chad...

I shouldnt of used a template column for item(0)...
besides it was hidden anyways :-d.
I used a bound column

Thanks,
Jon
Go to Top of Page
   

- Advertisement -