如何将Navigate Url附加到树视图节点

时间:2013-11-10 05:50:05

标签: c# asp.net

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

这里我包括treeview:

<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();
        }

    }

但是这给了我一个错误:

无效的列名称“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

1 个答案:

答案 0 :(得分:1)

您在ASPX中注册的事件是预览本身的DataBound事件。此事件具有与错误消息对应的EventHandler签名。在将所有节点绑定到数据之后调用它。处理TreeNodeDataBound事件应该可以解决问题。 更改ASPX文件中的以下位置(相关更改为DataBound - &gt; OnTreeNdeDataBound):

<asp:TreeView ID="TV_Question_Summary" runat="server" ImageSet="Simple" 
    ShowLines="True" OnTreeNodeDataBound="TV_Question_Summary_DataBound">
    ...