2014-04-04 59 views
10

當我正在調試一個網站時,我收到了「死亡的黃色屏幕」。錯誤消息是「值不能爲空。參數名稱:密鑰。」我試圖將formview綁定到gridview的選定索引。當我在我的selectedindexchanged方法中設置斷點時,所有東西似乎都能正確綁定,我可以查看我的formview的值,但是當我繼續運行它時,出現上述錯誤消息。我已經嘗試向formview添加datakeynames屬性並獲取相同的錯誤消息。我在這裏搜索和谷歌,看到一些結果,但似乎沒有解決或與我的問題有關。「值不能爲null參數名稱:密鑰」

部分代碼如下:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) 
{ 
    lblMessage.Text = ""; 
    cbCalled.Visible = true; 
    cbError.Visible = true; 
    cbVerbal.Visible = true; 
    btnSubmit.Visible = true; 
    FormView1.Visible = true; 
    FormView1.DataBind(); 
    FormView fv1 = FormView1; 
    Label PathCountLabel = (Label)fv1.FindControl("pathcountLabel"); 
    TextBox PathResult = (TextBox)fv1.FindControl("PathResultLabel"); 
    if ((PathCountLabel.Text != "1 of 1 biopsies") && (PathCountLabel.Text != "Only 1 Pathology Ordered")) 
    { 
     PathResult.BackColor = ColorTranslator.FromHtml("#FFFFAA"); 
    } 
} 

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
     Visible="False" DataKeyNames="PatientID" DataSourceID="SqlDataSource1" 
     onselectedindexchanged="GridView1_SelectedIndexChanged" AllowSorting="True" onsorting="GridView1_Sorting"> 
    <Columns> 
     <asp:CommandField ShowSelectButton="True" /> 
     <asp:BoundField DataField="PatientID" HeaderText="Patient Id" SortExpression="PatientID" /> 
     <asp:BoundField DataField="LastName" HeaderText="Last Name" 
      SortExpression="LastName" /> 
     <asp:BoundField DataField="FirstName" HeaderText="First Name" 
      SortExpression="FirstName" /> 
     <asp:BoundField DataField="PathCount" HeaderText="Path Count" 
      SortExpression="PathCount" /> 
     <asp:BoundField DataField="DateOfService" DataFormatString="{0:d}" 
      HeaderText="Date of Service" SortExpression="DateOfService" /> 
    </Columns> 
</asp:GridView> 
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
     ConnectionString="<%$ ConnectionStrings:PathologyConnectionString %>" 
     SelectCommand="SELECT * FROM [PatientDB]"> 
    </asp:SqlDataSource> 
<br /> 
</div> 
<div id="rightCol"> 
<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource2" 
    Width="708px"> 
    <EditItemTemplate> 
     LastName: 
     <asp:TextBox ID="LastNameTextBox" runat="server" 
      Text='<%# Bind("LastName") %>' /> 
     <br /> 
     FirstName: 
     <asp:TextBox ID="FirstNameTextBox" runat="server" 
      Text='<%# Bind("FirstName") %>' /> 
     <br /> 
     DOB: 
     <asp:TextBox ID="DOBTextBox" runat="server" 
      Text='<%# Bind("DOB") %>' /> 
     <br /> 
     PhoneNumber: 
     <asp:TextBox ID="PhoneNumberTextBox" runat="server" 
      Text='<%# Bind("PhoneNumber") %>' /> 
     <br /> 
     ChartNumber: 
     <asp:TextBox ID="ChartNumberTextBox" runat="server" 
      Text='<%# Bind("ChartNumber") %>' /> 
     <br /> 
     AccountNumber: 
     <asp:TextBox ID="AccountNumberTextBox" runat="server" 
      Text='<%# Bind("AccountNumber") %>' /> 
     <br /> 
     PathResult: 
     <asp:TextBox ID="PathResultTextBox" runat="server" 
      Text='<%# Bind("PathResult") %>' /> 
     <br /> 
     PreviousVisitNote: 
     <asp:TextBox ID="PreviousVisitNoteTextBox" runat="server" 
      Text='<%# Bind("PreviousVisitNote") %>' /> 
     <br /> 
     PathSlipNote: 
     <asp:TextBox ID="PathSlipNoteTextBox" runat="server" 
      Text='<%# Bind("PathSlipNote") %>' /> 
     <br /> 
     PathSlipCheckboxes: 
     <asp:TextBox ID="PathSlipCheckboxesTextBox" runat="server" 
      Text='<%# Bind("PathSlipCheckboxes") %>' /> 
     <br /> 
     <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" 
      CommandName="Update" Text="Update" /> 
     &nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server" 
      CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
    </EditItemTemplate> 
    <InsertItemTemplate> 
     LastName: 
     <asp:TextBox ID="LastNameTextBox" runat="server" 
      Text='<%# Bind("LastName") %>' /> 
     <br /> 
     FirstName: 
     <asp:TextBox ID="FirstNameTextBox" runat="server" 
      Text='<%# Bind("FirstName") %>' /> 
     <br /> 
     DOB: 
     <asp:TextBox ID="DOBTextBox" runat="server" 
      Text='<%# Bind("DOB") %>' /> 
     <br /> 
     PhoneNumber: 
     <asp:TextBox ID="PhoneNumberTextBox" runat="server" 
      Text='<%# Bind("PhoneNumber") %>' /> 
     <br /> 
     ChartNumber: 
     <asp:TextBox ID="ChartNumberTextBox" runat="server" 
      Text='<%# Bind("ChartNumber") %>' /> 
     <br /> 
     AccountNumber: 
     <asp:TextBox ID="AccountNumberTextBox" runat="server" 
      Text='<%# Bind("AccountNumber") %>' /> 
     <br /> 
     PathResult: 
     <asp:TextBox ID="PathResultTextBox" runat="server" 
      Text='<%# Bind("PathResult") %>' /> 
     <br /> 
     PreviousVisitNote: 
     <asp:TextBox ID="PreviousVisitNoteTextBox" runat="server" 
      Text='<%# Bind("PreviousVisitNote") %>' /> 
     <br /> 
     PathSlipNote: 
     <asp:TextBox ID="PathSlipNoteTextBox" runat="server" 
      Text='<%# Bind("PathSlipNote") %>' /> 
     <br /> 
     PathSlipCheckboxes: 
     <asp:TextBox ID="PathSlipCheckboxesTextBox" runat="server" 
      Text='<%# Bind("PathSlipCheckboxes") %>' /> 
     <br /> 
     <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" 
      CommandName="Insert" Text="Insert" /> 
     &nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server" 
      CausesValidation="False" CommandName="Cancel" Text="Cancel" /> 
    </InsertItemTemplate> 
    <ItemTemplate> 
     Last Name: 
     <asp:Label ID="LastNameLabel" runat="server" Text='<%# Bind("LastName") %>' /> 
     &nbsp;&nbsp;&nbsp;&nbsp; First Name: 
     <asp:Label ID="FirstNameLabel" runat="server" Text='<%# Bind("FirstName") %>' /> 
     &nbsp;&nbsp;&nbsp;&nbsp; DOB: 
     <asp:Label ID="DOBLabel" runat="server" Text='<%# Bind("DOB") %>' /> 
     &nbsp;&nbsp; 
     <br /> 
     <br /> 
     Phone Number: 
     <asp:Label ID="PhoneNumberLabel" runat="server" 
      Text='<%# Bind("PhoneNumber") %>' /> 
     &nbsp;&nbsp;&nbsp;&nbsp; Chart Number: 
     <asp:Label ID="ChartNumberLabel" runat="server" 
      Text='<%# Bind("ChartNumber") %>' /> 
     &nbsp;&nbsp;&nbsp; Account Number: 
     <asp:Label ID="AccountNumberLabel" runat="server" 
      Text='<%# Bind("AccountNumber") %>' /> 
     <br /> 
     <br /> 
     Biopsy Location: 
     <asp:Label ID="BiopsyLocationLabel" runat="server" Text='<%# Bind("BiopsyArea") %>'></asp:Label> 
     <br /> 
     <br /> 
     Path Result: 
     <br /> 
        <asp:TextBox ID="PathResultLabel" runat="server" 
      Text='<%# Bind("PathResult") %>' ReadOnly="True" TextMode="MultiLine" Width="600" Height="250" /> 

     <br /> 
     <br /> 
     Previous Visit Note:<br /> 
     <asp:TextBox ID="PreviousVisitNoteLabel" runat="server" 
      Text='<%# Bind("PreviousVisitNote") %>' ReadOnly="True" TextMode="MultiLine" Width="600" Height="250" /> 
     <br /> 
     <br /> 
     Pathology Lab Note:<br /> 
     <asp:TextBox ID="txtPathNote" runat="server" 
      Text='<%# Bind("PathNote") %>' ReadOnly="True" TextMode="MultiLine" Width="600" Height="150" /> 
     <br /> 
     <br /> 
     Note to DA/DT:<br /> 
     <asp:TextBox ID="txtDADTNote" runat="server" 
      Text='<%# Bind("DADTNote") %>' ReadOnly="True" TextMode="MultiLine" Width="600" Height="150" /> 
     <br /> 
     <br /> 
     Path Slip Note:<br /> 
     <asp:Label ID="PathSlipNoteLabel" runat="server" 
      Text='<%# Bind("PathSlipNote") %>' /> 
     <br /> 
     <br /> 
     Path Slip Checkboxes: 
     <br /> 
     <asp:Label ID="PathSlipCheckboxesLabel" runat="server" 
      Text='<%# Bind("PathSlipCheckboxes") %>' /> 
     <br /> 
     <br /> 
     Patient Message:<br /> 
     <ASPNetSpell:SpellTextBox ID="txtPatientMessage" runat="server" TextMode="MultiLine" 
    DictionaryLanguage="English (International), English (Medical)" Height="88px" 
    Width="597px" Text='<%# Bind("PatientMessage") %>' onKeyPress="return macro(event);"></ASPNetSpell:SpellTextBox> 
    <br /> 
    <asp:Label ID="pathcountLabel" runat="server" Text = '<%# Bind("PathCount") %>' Visible="false"></asp:Label> 
    </ItemTemplate> 
</asp:FormView> 
<asp:SqlDataSource ID="SqlDataSource2" runat="server" 
    ConnectionString="<%$ ConnectionStrings:PathologyConnectionString %>" 

    SelectCommand="SELECT [LastName], [FirstName], [DOB], [PhoneNumber], [ChartNumber], [AccountNumber], [PathResult], [PreviousVisitNote], [PathSlipNote], [PathSlipCheckboxes], [PathNote], [DADTNote], [BiopsyArea], [PatientMessage], [PathCount] FROM [PatientDB] WHERE ([PatientID] = @PatientID)"> 
    <SelectParameters> 
     <asp:ControlParameter ControlID="GridView1" Name="PatientID" 
      PropertyName="SelectedValue" Type="Int32" /> 
    </SelectParameters> 
</asp:SqlDataSource> 

我從YSOD

Server Error in '/' Application. 
-------------------------------------------------------------------------------- 


Value cannot be null. 
Parameter name: key 
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.ArgumentNullException: Value cannot be null. 
Parameter name: key 

Source Error: 


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 



[ArgumentNullException: Value cannot be null. 
Parameter name: key] 
    System.Collections.Generic.Dictionary`2.FindEntry(TKey key) +10627293 
    System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value) +12 
    Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.GetLiteralTraceData(LiteralControl literal, TraceData& data) +97 
    Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.GetTraceData(Object renderedObject) +421 
    Microsoft.VisualStudio.Web.PageInspector.Runtime.WebForms.SelectionMappingRenderTraceListener.EndRendering(TextWriter writer, Object renderedObject) +79 
    System.Web.UI.RenderTraceListenerList.EndRendering(TextWriter writer, Object renderedObject) +58 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +142 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    ASPNetSpell.SpellTextBox.Render(HtmlTextWriter writer) +6035 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.WebControls.TableCell.RenderContents(HtmlTextWriter writer) +57 
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10 
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 
    System.Web.UI.WebControls.FormViewRow.Render(HtmlTextWriter writer) +38 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.WebControls.Table.RenderContents(HtmlTextWriter writer) +211 
    System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer) +32 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer) +10 
    System.Web.UI.WebControls.FormView.Render(HtmlTextWriter writer) +86 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.Control.Render(HtmlTextWriter writer) +10 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +102 
    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +32 
    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +53 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +40 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.Control.Render(HtmlTextWriter writer) +10 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128 
    System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8 
    System.Web.UI.Page.Render(HtmlTextWriter writer) +29 
    System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100 
    System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386 




-------------------------------------------------------------------------------- 
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.18446 
+0

我不能從您發佈的代碼中看到任何明顯的東西。你可以添加YSOD的屏幕截圖嗎?是否有堆棧跟蹤或任何可以幫助人們與您一起調試的內容?你有任何服務器端代碼formview事件? – philreed

+0

我添加了堆棧跟蹤信息,除了上面列出的有關從formview獲取某些信息的信息外,我沒有任何與formview相關的服務器端代碼。 – user3064073

+0

這是很多需要閱讀的代碼。你能縮小你的問題嗎? –

回答

0

我刷新了formview1的sqldatasource2,當我這樣做時允許我刷新formview1的模式和鍵。當我做到這一點時,所以我重新構建了表單視圖以查找需要的方式,然後再次停止工作。我確定它來自aspnetspell:spelltextbox控件。我下載了最新版本,現在可以使用。

+0

這不應該是被接受的答案。問題在於Visual Studio做了什麼錯誤的事,與SqlDataSource或任何其他Web窗體控件無關。 – Richard

0

我的建議是測試您的數據添加的堆棧跟蹤。你似乎試圖將一個空值綁定到控件。確保DataSet中沒有從數據庫返回的空值。它應該是您的第一個停靠港。

+0

我檢查了所有正在返回的數據,並且沒有空值。 – user3064073

17

我試過你所說的一切,它沒有工作。 但是,我發現了一個解決方法,出於某種原因,我不知道,工作。 我將此添加到我的web.config文件:

<add key="PageInspector:ServerCodeMappingSupport" value="Disabled" /> 

和它的工作對我來說:d

+1

浪費了半天的時間來解決這個問題,終於從這裏得到了..很好,謝謝你.. !!! –

5

嘗試關閉Visual Studio和並訪問同一頁面。它應該工作。我也面臨同樣的例外。如果你看到異常,它會指向導致問題的Visual Studio的PageInspector。不知道爲什麼VS搞亂了應用程序加載。

+0

哇...現在時間搞清楚爲什麼發生這種情況大聲笑 –

0

我只是有這個問題,對我來說,從代碼中添加LiteralControl落後時發生。 Text屬性爲null,這會擾亂PageInspector,因此只需將其設置爲string.Empty。

我建議反對關閉功能只是爲了解決這樣的錯誤,因爲當不同的機器上的不同開發人員繼承你的代碼時,他們將會有完全相同的問題。

相關問題