getting conversion error

I am creating a website using a VB

Error: if I print getID1
Conversion from string to type 'Integer' is not valid.

Error: if I print getID2
NullReferenceException was unhandled by user code. Object reference not set to an instance of an object.


.aspx file


<asp:DataList ID="DataList1" runat="server" DataKeyField="ID" OnDeleteCommand="DeleteCommand">
        <asp:ImageButton runat="server" ID="deleteIB" CommandName="Delete" ImageUrl="x-icon.png"  />
        <%# DataBinder.Eval(Container.DataItem, "ID") %>


.aspx.vb file


Dim ds As DataSet = New DataSet()
Dim dt As DataTable = New DataTable()
Dim dt As DataTable = New DataTable()
dt.Columns.Add(New DataColumn("ID", GetType(Int32)))
Dim dr As DataRow
While reader.Read()
    dr = dt.NewRow()
    dr(0) = "<a href='" & reader(3) & "' target='_blank'>" & reader(2) & "</a>"
End While

Protected Sub DeleteCommand(ByVal source As Object, ByVal e As DataListCommandEventArgs)
    'Dim getID1 As Integer = CInt(DataList1.DataKeys(e.Item.ItemIndex))
    Dim getID2 As String = (CType(e.Item.FindControl("ID"), Label)).Text
    ErrorL.Text = getID2
End Sub

the first error (my vb is rusty), i think you need brackets:

Dim getID1 As Integer = CInt(DataList1.DataKeys[e.Item.ItemIndex]
Dim getID1 As String = DataList1.DataKeys[e.Item.ItemIndex].ToString()

the second error, as far as i can tell, you don't have a control with an id of "ID".