ASP.NET FormView中编辑时的RadioButtonList控件报错,找不到匹配的Value

来源:互联网 发布:数据报表格式 编辑:程序博客网 时间:2024/05/16 15:17

现象:

Item模板数据源采用视图,其中的出发地(StartLocation)列将原表中的id标示转换为对应的文字了;Edit模板中用RadioButtonList显示出发地显示为文字,值为其对应id。报错提示如题。

故障原因:

苦思三天,找到原因。Item模板切换到Edit模板时,会根据Item中的字段内容到RadioButtonList的值中寻找对应的选项,但是Item的字段内容为文字,而RadioButtonList值为id,找不到匹配的值。

解决方法:

将前台视图中的StartLocation字段定义为id,增加vStartLocation字段,用来显示文字内容。在FormView的Item模板中用vStartLocation字段显示,在Edit模板中将RadionButtonList的SelectedValue绑定到StartLocation。

 

视图:

SELECT    dbo.aspnet_Users.UserName AS LastUpdateUserName, ……

                      dbo.Sys_Dictionary.dicValuesAS vLineType, dbo.wcxView_StartLocationFromSubcompany.scProvince ASvStartLocation,

                     Sys_Dictionary_1.dicValues AS vEndLocation,dbo.Product_TravelLines.StartLocation, dbo.Product_TravelLines.EndLocation,

                     dbo.Product_TravelLines.LineType

FROM        dbo.Product_TravelLines INNER JOIN……

Item模板:

<asp:LabelID="Label_StartLocation"runat="server"

                            Text='<%# Bind("vStartLocation")%>' />

Edit模板:

<asp:RadioButtonListID="RadioButtonList_eStartLocation"runat="server"

DataSourceID="SqlDataSource_StartLocation"     DataTextField="scProvince"

DataValueField="ID"RepeatDirection="Horizontal"

SelectedValue='<%# Bind("StartLocation")%>' >

</asp:RadioButtonList>

0 0