Hi
I have a datagrid wich consits of 6 items, 5 of them are visible but the 6'th value isn't visible and it can also be null. When I loop through the datagrid I get this error "System.NullReferenceException: Object reference not set to an instance of an object"
That error appears when it somes to the "If TextFileName.Text Is Nothing Then" line.
Am I doing this the wrong way or..? I don't know and could really use some help.
Here's the code I use....
***********************************
Dim TextFileName As TextBox
Dim FsObj As FileStream
For Each dgi In MyDataGrid.Items
Select Case dgi.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
'Use CartID to identify what item to delete or update
CartID = MyDataGrid.DataKeys(dgi.ItemIndex)
TextBoxQuantity = CType(dgi.FindControl("intQty"
, TextBox)
TextFileName = CType(dgi.FindControl("FileName"
, TextBox)
If CType(dgi.FindControl("DeleteFromCartCheckBox"
, CheckBox).Checked = True Or (TextBoxQuantity.Text) = 0 Then
'Remove from Cart Code Here
If TextFileName.Text Is Nothing Then
Else
If File.Exists(TextFileName.Text.ToString) Then
File.Delete(TextFileName.Text.ToString)
'Response.Write ("Finns"
End If
End If
******************************************************
And a bit of the datagrid ....
<asp:TemplateColumn ItemStyle-Width="50" ItemStyle-BorderWidth="0" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" Visible="False" runat="server">
<ItemTemplate>
<asp:Label ID="lblFileName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileName"
%>'/>
</ItemTemplate>
</asp:TemplateColumn>
Best Regards
/M
I have a datagrid wich consits of 6 items, 5 of them are visible but the 6'th value isn't visible and it can also be null. When I loop through the datagrid I get this error "System.NullReferenceException: Object reference not set to an instance of an object"
That error appears when it somes to the "If TextFileName.Text Is Nothing Then" line.
Am I doing this the wrong way or..? I don't know and could really use some help.
Here's the code I use....
***********************************
Dim TextFileName As TextBox
Dim FsObj As FileStream
For Each dgi In MyDataGrid.Items
Select Case dgi.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem
'Use CartID to identify what item to delete or update
CartID = MyDataGrid.DataKeys(dgi.ItemIndex)
TextBoxQuantity = CType(dgi.FindControl("intQty"
TextFileName = CType(dgi.FindControl("FileName"
If CType(dgi.FindControl("DeleteFromCartCheckBox"
'Remove from Cart Code Here
If TextFileName.Text Is Nothing Then
Else
If File.Exists(TextFileName.Text.ToString) Then
File.Delete(TextFileName.Text.ToString)
'Response.Write ("Finns"
End If
End If
******************************************************
And a bit of the datagrid ....
<asp:TemplateColumn ItemStyle-Width="50" ItemStyle-BorderWidth="0" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" Visible="False" runat="server">
<ItemTemplate>
<asp:Label ID="lblFileName" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "FileName"
</ItemTemplate>
</asp:TemplateColumn>
Best Regards
/M