我得到一個空的異常拋出。你能幫我理解爲什麼嗎?代碼後面的空例外
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Data.SqlClient;
namespace ProjectEta
{
public partial class File_Viewer : System.Web.UI.Page
{
public string CurDate = DateTime.Today.ToString("dd/MM/yyyy");
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
TextBox OpenDateTextBox = (TextBox)e.Item.FindControl("OpenDateTextBox");
OpenDateTextBox.Text = "12/12/2012";
DataRowView rowView = e.Item.DataItem as DataRowView;
string myCurDate = rowView["OpenDate"].ToString();
}
}
}
}
這是aspx。
<InsertItemTemplate>
<tr style="font-size: smaller; text-align: center;">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td> </td>
<td>
<asp:DropDownList ID="ProcessorIdDrop" runat="server" DataSourceID="UserNames" DataTextField="Name" Text='<%# Bind("ProcessorId") %>' ></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="UserNames" DataTextField="Name" Text='<%# Bind("UnderwriterId") %>' ></asp:DropDownList>
</td>
<td>
<asp:DropDownList ID="DropDownList5" runat="server" DataSourceID="FileStatusTypes" DataTextField="FileStat" Text='<%# Bind("Status") %>' ></asp:DropDownList>
</td>
<td>
<asp:TextBox ID="OpenDateTextBox" runat="server" Text='<%# Bind("OpenDate") %>' />
</td>
<td>
<asp:Label ID="CloseDateTextBox" runat="server" Text='<%# Eval("CloseDate") %>' />
</td>
<td>
<asp:TextBox ID="BorrowerIdTextBox" runat="server" Text='<%# Bind("BorrowerId") %>' />
</td>
<td>
<asp:DropDownList ID="Lender_LenderIdDrop" runat="server" DataSourceID="LenderNames" DataTextField="Name" DataValueField="Name" Text='<%# Bind("Lender_LenderId") %>'></asp:DropDownList>
</td>
<td>
<asp:TextBox ID="Client_ClientIdTextBox" runat="server" Text='<%# Bind("Client_ClientId") %>' />
</td>
</tr>
</InsertItemTemplate>
我跟着這個職位,how to set label text inside listview from code behind的建議,但我得到一個「對象引用不設置到對象的實例」。我以爲OpenDateTextBox是aspx中文本框的ID,所以我不會遇到這個問題。我得到這是一個noob問題,但幫助將不勝感激。
您正在使用的變量之一包含'null',可能是因爲其初始化程序返回'null'。讓我們知道哪條線導致這一點。 –
你可以粘貼堆棧跟蹤嗎? –
它也有可能'e.Item.FindControl(「OpenDateTextBox」)'返回null,因爲它無法找到它。 –