0

我有一个树形视图,显示最近插入的问题的摘要。我试图从树视图的数据绑定事件中附加 NavigateUrl。

这里我包括树视图:

<asp:TreeView ID="TV_Question_Summary" runat="server" ImageSet="Simple" 
    ShowLines="True" ondatabound="TV_Question_Summary_DataBound">
        <DataBindings>
            <asp:TreeNodeBinding DataMember="ParentNode" FormatString=" {0}" TextField="Inquiry_id" ValueField="Inquiry_id"/>
            <asp:TreeNodeBinding DataMember="Node" FormatString=" {0}" TextField="body" ValueField="Inquiry_id" />
        </DataBindings>
</asp:TreeView>

这段代码将inquiryid值绑定到每个节点:

 public void TV_Question_Summary_DataBound(object sender, TreeNodeEventArgs e)
    {
        e.Node.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid=" + e.Node.Value;
    }

这个错误是如何发生的编译时间:

Error   3   No overload for 'TV_Question_Summary_DataBound' matches delegate 'System.EventHandler'  C:\Documents and Settings\Vishal\My Documents\Visual Studio 2005\WebSites\OmInvestmentStockMarketing_new\Admin\MasterPage.master    1   1   C:\...\OmInvestmentStockMarketing_new\

- - - - - - - - - - - - - - - - 更新 - - - - - - - - - ------------

我的存储过程:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[ViewSummaryOfQuestions]
AS
BEGIN
SET NOCOUNT ON;
SELECT tbl_Inquiry_History.Inquiry_id, tbl_Question.body
FROM   tbl_Inquiry_History INNER JOIN
       tbl_Question ON tbl_Inquiry_History.Inquiry_id = tbl_Question.Inquiry_id
WHERE(tbl_Question.IsCount='False')
--UPDATE [OmStocks].[dbo].[tbl_Question]
   --SET [IsCount] = 'True'
--WHERE (IsCount='False')
END

并返回输出:

-------------------------------------------------
Inquiry_id      body
-------------------------------------------------
119 -CDNE-2013  i just want service ...
119 -UXCY-2013  I just want to service please...
119 -CDNE-2013  hurry up...
-------------------------------------------------

为了将此输出绑定到树视图,我使用以下代码:

void fill_Tree()
    {
        using (SqlConnection conn = Util.GetConnection())
        {
            conn.Open();
            SqlCommand SqlCmd = new SqlCommand("Select * from tbl_Inquiry_History", conn);
            SqlDataReader Sdr = SqlCmd.ExecuteReader();
            SqlCmd.Dispose();
            string[,] ParentNode = new string[100, 2];
            int count = 0;
            while (Sdr.Read())
            {

                ParentNode[count, 0] = Sdr.GetValue(Sdr.GetOrdinal("Inquiry_id")).ToString();
                ParentNode[count++, 1] = Sdr.GetValue(Sdr.GetOrdinal("Inquiry_id")).ToString();

            }
            Sdr.Close();
            for (int loop = 0; loop < count; loop++)
            {
                TreeNode root = new TreeNode();
                root.Text = ParentNode[loop, 1];
                //root.Target = "_blank";
                root.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid="+ ParentNode[loop, 1];
                SqlCommand Module_SqlCmd = new SqlCommand("Select * from tbl_Question where (Inquiry_id =" + ParentNode[loop, 0] + "AND IsCount='False')", conn);
                SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();
                while (Module_Sdr.Read())
                {
                    TreeNode child = new TreeNode();
                    child.Text = Module_Sdr.GetValue(Module_Sdr.GetOrdinal("body")).ToString();
                    //child.Target = "_blank";
                    child.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid="+ParentNode[loop, 0];
                    root.ChildNodes.Add(child);
                }

                Module_Sdr.Close();
                TV_Question_Summary.Nodes.Add(root);

            }
            TV_Question_Summary.CollapseAll();
        }

    }

但这给了我这样的错误:

“/OmInvestmentStockMarketing_new”应用程序中的服务器错误。

列名“CDNE”无效。

说明:执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

Exception Details: System.Data.SqlClient.SqlException: Invalid column name 'CDNE'.

Source Error: 


Line 146:                root.NavigateUrl = "~/Admin/OWM_Inquiry.aspx?inquiryid="+ ParentNode[loop, 1];
Line 147:                SqlCommand Module_SqlCmd = new SqlCommand("Select * from tbl_Question where (Inquiry_id =" + ParentNode[loop, 0] + "AND IsCount='False')", conn);
Line 148:                SqlDataReader Module_Sdr = Module_SqlCmd.ExecuteReader();
Line 149:                while (Module_Sdr.Read())
Line 150:                {

Source File: c:\Documents and Settings\Vishal\My Documents\Visual Studio 2005\WebSites\OmInvestmentStockMarketing_new\Admin\MasterPage.master.cs    Line: 148 

Stack Trace: 


[SqlException (0x80131904): Invalid column name 'CDNE'.]
   System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826
   System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
   System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
   System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
   System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
   System.Data.SqlClient.SqlDataReader.get_MetaData() +83
   System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
   System.Data.SqlClient.SqlCommand.ExecuteReader() +89
   Admin_MasterPage.fill_Tree() in c:\Documents and Settings\Vishal\My Documents\Visual Studio 2005\WebSites\OmInvestmentStockMarketing_new\Admin\MasterPage.master.cs:148
   Admin_MasterPage.Page_Load(Object sender, EventArgs e) in c:\Documents and Settings\Vishal\My Documents\Visual Studio 2005\WebSites\OmInvestmentStockMarketing_new\Admin\MasterPage.master.cs:101
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Control.LoadRecursive() +141
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
4

1 回答 1

1

The event you register in the ASPX is the DataBound event for the preview itself. This event has a EventHandler signature that corresponds to the the error message. It is called once after all the nodes have been bound to the data. Handling the TreeNodeDataBound event instead should solve the problem. Change the following spot in your ASPX-file (the relevant change is DataBound -> OnTreeNdeDataBound):

<asp:TreeView ID="TV_Question_Summary" runat="server" ImageSet="Simple" 
    ShowLines="True" OnTreeNodeDataBound="TV_Question_Summary_DataBound">
    ...                                                                                
于 2013-11-10T07:20:05.873 回答