ListView1 FindControl未将对象实例化
前台代码
<asp:ListView ID="ListView1" runat="server" DataKeyNames="日期"
DataSourceID="SqlDataSource1" onitemcommand="ListView1_ItemCommand">
<AlternatingItemTemplate>
<table style="width: 100%;">
<tr>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="select"><%# Eval("标题") %></asp:LinkButton>
</td>
<td style="width: 300px; height: 30px">
<%# Eval("日期") %>
</td>
</tr>
</table>
</AlternatingItemTemplate>
<EmptyDataTemplate>
未返回数据。
</EmptyDataTemplate>
<ItemSeparatorTemplate></ItemSeparatorTemplate>
<ItemTemplate>
<table style="width: 100%;">
<tr>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="select"><%# Eval("标题") %></asp:LinkButton>
</td>
<td style="width: 300px; height: 30px">
<%# Eval("日期") %>
</td>
</tr>
</table>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server" style="">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<SelectedItemTemplate>
<div style="color: #FF6600; background-color: #CCCCCC; border: 1px solid #666666">
<table style="width: 100%;">
<tr>
<td>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="cancel">收起</asp:LinkButton><br />
<%# Eval("标题") %>
</td>
</tr>
<tr>
<td>
<%# Eval("正文") %></td>
</tr>
<tr>
<td style="text-align: right">
<%# Eval("发起人") %> <%# Eval("日期") %>
</td>
</tr>
</table>
</div>
<div style="padding: 20px">
<asp:ListView ID="ListView2" runat="server" DataSourceID="SqlDataSource2">
<AlternatingItemTemplate>
<li style="background-color: #FFF8DC;">日期:
<asp:Label ID="评论Label" runat="server" Text='<%# Eval("评论") %>' />
<br />
评论人:
<asp:Label ID="评论人Label" runat="server" Text='<%# Eval("评论人") %>' />
<asp:Label ID="日期Label" runat="server" Text='<%# Eval("日期") %>' />
<br />
</li>
</AlternatingItemTemplate>
<EmptyDataTemplate>
未返回数据。
</EmptyDataTemplate>
<ItemSeparatorTemplate>
<br />
</ItemSeparatorTemplate>
<ItemTemplate>
<li style="background-color: #DCDCDC;color: #000000;">
<asp:Label ID="评论Label" runat="server" Text='<%# Eval("评论") %>' />
<br />
评论人:
<asp:Label ID="评论人Label" runat="server" Text='<%# Eval("评论人") %>' />
<asp:Label ID="日期Label" runat="server" Text='<%# Eval("日期") %>' />
<br />
</li>
</ItemTemplate>
<LayoutTemplate>
<ul ID="itemPlaceholderContainer" runat="server"
style="font-family: Verdana, Arial, Helvetica, sans-serif;">
<li runat="server" id="itemPlaceholder" />
</ul>
<div style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True"
ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
</asp:ListView>
<br />
<asp:FormView ID="FormView1" runat="server" DataKeyNames="标题"
DataSourceID="SqlDataSource2" DefaultMode="Insert" BorderColor="#66CCFF"
BorderStyle="Solid" Width="408px">
<InsertItemTemplate>
<asp:TextBox ID="日期TextBox" runat="server" Text='<%# Bind("日期") %>' />
<asp:TextBox ID="标题TextBox" runat="server" Text='<%# Bind("标题") %>' />
<br />
<asp:Label ID="Label4" runat="server" BackColor="#66CCFF" Text="发表评论"
Width="100%"></asp:Label>
<asp:TextBox ID="评论TextBox" runat="server" Height="200px" Text='<%# Bind("评论") %>'
Width="400px" />
<br />
<br />
评论人:<asp:TextBox ID="评论人TextBox" runat="server" Text='<%# Bind("评论人") %>' />
<br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="发表评论" />
</InsertItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [评论] WHERE ([标题] = @标题) ORDER BY [日期] DESC"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [评论] WHERE [标题] = @original_标题 AND [日期] = @original_日期 AND (([评论] = @original_评论) OR ([评论] IS NULL AND @original_评论 IS NULL)) AND (([评论人] = @original_评论人) OR ([评论人] IS NULL AND @original_评论人 IS NULL))"
InsertCommand="INSERT INTO [评论] ([日期], [标题], [评论], [评论人]) VALUES (@日期, @标题, @评论, @评论人)"
OldValuesParameterFormatString="original_{0}"
UpdateCommand="UPDATE [评论] SET [日期] = @日期, [评论] = @评论, [评论人] = @评论人 WHERE [标题] = @original_标题 AND [日期] = @original_日期 AND (([评论] = @original_评论) OR ([评论] IS NULL AND @original_评论 IS NULL)) AND (([评论人] = @original_评论人) OR ([评论人] IS NULL AND @original_评论人 IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_标题" Type="String" />
<asp:Parameter Name="original_日期" Type="DateTime" />
<asp:Parameter Name="original_评论" Type="String" />
<asp:Parameter Name="original_评论人" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="日期" Type="DateTime" />
<asp:Parameter Name="标题" Type="String" />
<asp:Parameter Name="评论" Type="String" />
<asp:Parameter Name="评论人" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="ListView1" Name="标题"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="日期" Type="DateTime" />
<asp:Parameter Name="评论" Type="String" />
<asp:Parameter Name="评论人" Type="String" />
<asp:Parameter Name="original_标题" Type="String" />
<asp:Parameter Name="original_日期" Type="DateTime" />
<asp:Parameter Name="original_评论" Type="String" />
<asp:Parameter Name="original_评论人" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</SelectedItemTemplate>
</asp:ListView>
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
ListView1.SelectedIndex = e.Item.DataItemIndex;
FormView fv = (FormView)e.Item.FindControl("FormView1");
TextBox tx1 = (TextBox)fv.FindControl("日期TextBox");//此行提示未将对象实例化
tx1.Text = DateTime.Now.ToString();
//LinkButton lbt = (LinkButton)e.Item.FindControl("LinkButton1");
TextBox tx2 = (TextBox)fv.FindControl("标题TextBox");
tx2.Text = ListView1.SelectedValue.ToString();
}