Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.net,如何制作我的下拉列表_Asp.net_Drop Down Menu - Fatal编程技术网

ASP.net,如何制作我的下拉列表

ASP.net,如何制作我的下拉列表,asp.net,drop-down-menu,Asp.net,Drop Down Menu,我的ASP.net页面上有一个下拉列表。它包含另一个表中的主键值。它使用这些值将其放入一个新的交集表中 我的问题是,为了可读性/可用性,显示主键本身并不理想。我更愿意显示相应的名称字段,但仍然要插入主键。我曾尝试更改datatextfield,将value字段保留为pk,并选择其中一列或两列,但当我尝试输入时,返回的结果是无法接受null值 有人能帮忙吗 <InsertItemTemplate> <asp:DropDownList ID="DropDownList4"

我的ASP.net页面上有一个下拉列表。它包含另一个表中的主键值。它使用这些值将其放入一个新的交集表中

我的问题是,为了可读性/可用性,显示主键本身并不理想。我更愿意显示相应的名称字段,但仍然要插入主键。我曾尝试更改datatextfield,将value字段保留为pk,并选择其中一列或两列,但当我尝试输入时,返回的结果是无法接受null值

有人能帮忙吗

<InsertItemTemplate>
     <asp:DropDownList ID="DropDownList4" runat="server" DataSourceID="SqlDataSource4" DataTextField="BoatID" DataValueField="BoatID">
     </asp:DropDownList>
     <asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:Rowing ClubConnectionString %>" SelectCommand="SELECT [BoatID] FROM [Boat]"></asp:SqlDataSource>

</InsertItemTemplate>

谢谢大家!

以下是当datatextfield更改为boat name且sql包含boat name列时,尝试添加到表时出现的错误页面:

“/”应用程序中出现服务器错误

无法在“Rowing Club.dbo.SessionBoats”表的“BoatID”列中插入值NULL;列不允许空值。插入失败。 声明已终止

描述:执行当前web请求期间发生未处理的异常。请查看堆栈跟踪以了解有关错误的更多信息以及错误在代码中的起源

异常详细信息:System.Data.SqlClient.SqlException:无法在“Rowing Club.dbo.SessionBoats”表的“BoatID”列中插入值NULL;列不允许空值。插入失败。 声明已终止

源错误:

在执行当前web请求期间生成了未经处理的异常。有关异常的起源和位置的信息可以使用下面的异常堆栈跟踪来识别

堆栈跟踪:

[SqlException(0x80131904):无法将值NULL插入表“Rowing Club.dbo.SessionBoats”的列“BoatID”中;列不允许为NULL。插入失败。 该声明已终止。] System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection,Action
1 wrapCloseInAction)+1767866
System.Data.SqlClient.SqlInternalConnection.OneError(SqlException异常,布尔断开连接,操作
1 wrapCloseInAction)+5352418 System.Data.SqlClient.TdsParser.throweexception和warning(TdsParserStateObject stateObj,布尔调用方连接锁,布尔异步关闭)+244 System.Data.SqlClient.TdsParser.TryRun(RunBehavior RunBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj,Boolean&dataReady)+1691 System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds、RunBehavior、String ResetOptions String)+269 System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、Boolean async、Int32超时、任务和任务、Boolean asyncWrite、SqlDataReader ds)+1406 System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior、RunBehavior RunBehavior、Boolean returnStream、String方法、TaskCompletionSource
1完成、Int32超时、任务和任务、Boolean asyncWrite)+177
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource
1 completion,String methodName,Boolean sendToPipe,Int32超时,Boolean asyncWrite)+205 System.Data.SqlClient.SqlCommand.ExecuteNonQuery()+160 System.Web.UI.WebControls.SqlDataSourceView.ExecuteDbCommand(DbCommand命令,DataSourceOperation操作)+380 System.Web.UI.WebControls.SqlDataSourceView.ExecuteInsert(IDictionary值)+399 System.Web.UI.DataSourceView.Insert(IDictionary值,DataSourceViewOperationCallback)+81 System.Web.UI.WebControls.DetailsView.HandleInsert(String commandArg,Boolean causesValidation)+365 System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e、Boolean causesValidation、String validationGroup)+584 System.Web.UI.WebControls.DetailsView.OnBubbleEvent(对象源,事件参数)+89 System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs-args)+37 System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(对象源,事件参数)+80 System.Web.UI.Control.RaiseBubbleEvent(对象源,EventArgs-args)+37 System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)+121 System.Web.UI.WebControl.LinkButton.RaisePostBackEvent(String eventArgument)+156 System.Web.UI.WebControl.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)+10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl,String eventArgument)+13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)+9528682
System.Web.UI.Page.ProcessRequestMain(布尔值includeStagesBeforeAsyncPoint,布尔值includeStagesAfterAsyncPoint)+1724

更改DataTextField,并将name字段添加到SQL查询中。这是正确的方法。我知道你说它不起作用,但我们确信这至少是解决方案的一部分。完成后,请告诉我们确切的异常是什么以及它发生在哪一行。请用这些信息更新您的问题。上面的添加是否说明了问题?是的,这与您试图插入数据库的数据有关。您应该检查空白(null)数据。