我收到一个空异常。你能帮我理解为什么吗?
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>
我遵循了这篇文章的建议,如何从后面的代码中设置列表视图中的标签文本,但我得到一个“对象引用未设置为对象的实例”。我想因为 OpenDateTextBox 是 aspx 中文本框的 ID,所以我不会遇到这个问题。我知道这是一个菜鸟问题,但我们将不胜感激。