问题描述
VB.NET做的,我在datalist里面放了个freetextbox,可是更新数据的时候出现了以下报错...无法解决,请高手指点...报错无法将类型为“FreeTextBoxControls.FreeTextBox”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”。.aspx代码<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ConnectionStrings:zongConnectionString4%>"DeleteCommand="DELETEFROM[news]WHERE[news_id]=@news_id"InsertCommand="INSERTINTO[news]([news_bt],[news_date],[news_beizhu],[news_neirong],[news_pic4],[news_pic3],[news_pic2],[news_pic1])VALUES(@news_bt,@news_date,@news_beizhu,@news_neirong,@news_pic4,@news_pic3,@news_pic2,@news_pic1)"SelectCommand="SELECT[news_id],[news_bt],[news_date],[news_beizhu],[news_neirong],[news_pic4],[news_pic3],[news_pic2],[news_pic1]FROM[news]WHERE([news_id]=@news_id)ORDERBY[news_id]DESC"UpdateCommand="UPDATE[news]SET[news_bt]=@news_bt,[news_date]=@news_date,[news_beizhu]=@news_beizhu,[news_neirong]=@news_neirong,[news_pic4]=@news_pic4,[news_pic3]=@news_pic3,[news_pic2]=@news_pic2,[news_pic1]=@news_pic1WHERE[news_id]=@news_id"><SelectParameters><asp:QueryStringParameterName="news_id"QueryStringField="news_id"Type="Int32"/></SelectParameters><DeleteParameters><asp:ParameterName="news_id"Type="Int32"/></DeleteParameters><UpdateParameters><asp:ParameterName="news_bt"Type="String"/><asp:ParameterName="news_date"Type="DateTime"/><asp:ParameterName="news_beizhu"Type="String"/><asp:ParameterName="news_neirong"Type="String"/><asp:ParameterName="news_pic4"Type="String"/><asp:ParameterName="news_pic3"Type="String"/><asp:ParameterName="news_pic2"Type="String"/><asp:ParameterName="news_pic1"Type="String"/><asp:ParameterName="news_id"Type="Int32"/></UpdateParameters><InsertParameters><asp:ParameterName="news_bt"Type="String"/><asp:ParameterName="news_date"Type="DateTime"/><asp:ParameterName="news_beizhu"Type="String"/><asp:ParameterName="news_neirong"Type="String"/><asp:ParameterName="news_pic4"Type="String"/><asp:ParameterName="news_pic3"Type="String"/><asp:ParameterName="news_pic2"Type="String"/><asp:ParameterName="news_pic1"Type="String"/></InsertParameters></asp:SqlDataSource><asp:DataListID="DataList1"runat="server"DataKeyField="news_id"DataSourceID="SqlDataSource1"OnUpdateCommand="DataList1_UpdateCommand"Width="324px"><ItemTemplate>新闻序号:<asp:LabelID="news_idLabel"runat="server"Text='<%#Eval("news_id")%>'/><br/>新闻标题:<asp:TextBoxID="TextBox1"runat="server"Text='<%#Eval("news_bt")%>'Width="250px"></asp:TextBox><br/>日 期:<asp:TextBoxID="TextBox2"runat="server"Text='<%#Eval("news_date")%>'Width="150px"></asp:TextBox><br/>备 注:<asp:TextBoxID="TextBox3"runat="server"Height="50px"Text='<%#Eval("news_beizhu")%>'TextMode="MultiLine"Width="300px"></asp:TextBox><br/>内 容:<br/><FTB:FreeTextBoxID="FreeTextBox1"runat="server"AllowHtmlMode="False"AssemblyResourceHandlerPath=""AutoConfigure=""AutoGenerateToolbarsFromString="True"AutoHideToolbar="True"AutoParseStyles="True"BackColor="158,190,245"BaseUrl=""BreakMode="Paragraph"ButtonDownImage="False"ButtonFileExtention="gif"ButtonFolder="Images"ButtonHeight="20"ButtonImagesLocation="InternalResource"ButtonOverImage="False"ButtonPath=""ButtonSet="Office2003"ButtonWidth="21"ClientSideTextChanged=""ConvertHtmlSymbolsToHtmlCodes="False"DesignModeBodyTagCssClass=""DesignModeCss=""DisableIEBackButton="False"DownLevelCols="50"DownLevelMessage=""DownLevelMode="TextArea"DownLevelRows="10"EditorBorderColorDark="128,128,128"EditorBorderColorLight="128,128,128"EnableHtmlMode="True"EnableSsl="False"EnableToolbars="True"Focus="False"FormatHtmlTagsToXhtml="True"GutterBackColor="129,169,226"GutterBorderColorDark="128,128,128"GutterBorderColorLight="255,255,255"Height="350px"HelperFilesParameters=""HelperFilesPath=""HtmlModeCss=""HtmlModeDefaultsToMonoSpaceFont="True"ImageGalleryPath="~/images/"ImageGalleryUrl="ftb.imagegallery.aspx?rif={0}&cif={0}"InstallationErrorMessage="InlineMessage"JavaScriptLocation="InternalResource"Language="en-US"PasteMode="Default"ReadOnly="False"RemoveScriptNameFromBookmarks="True"RemoveServerNameFromUrls="True"RenderMode="NotSet"ScriptMode="External"ShowTagPath="False"SslUrl="/."StartMode="DesignMode"StripAllScripting="False"SupportFolder="/aspnet_client/FreeTextBox/"TabIndex="-1"TabMode="InsertSpaces"Text='<%#Eval("news_neirong")%>'TextDirection="LeftToRight"ToolbarBackColor="Transparent"ToolbarBackgroundImage="True"ToolbarImagesLocation="InternalResource"ToolbarLayout="ParagraphMenu,FontFacesMenu,FontSizesMenu,FontForeColorsMenu|Bold,Italic,Underline,Strikethrough;Superscript,Subscript,RemoveFormat|JustifyLeft,JustifyRight,JustifyCenter,JustifyFull;BulletedList,NumberedList,Indent,Outdent;CreateLink,Unlink,InsertImage,InsertRule|Cut,Copy,Paste;Undo,Redo,Print"ToolbarStyleConfiguration="NotSet"UpdateToolbar="True"UseToolbarBackGroundImage="True"Width="600px"></FTB:FreeTextBox><asp:TextBoxID="TextBox4"ControlID="freetextbox1"runat="server"Height="84px"Width="592px"Text='<%#Eval("news_neirong")%>'TextMode="MultiLine"></asp:TextBox><br/><asp:ButtonID="Button1"runat="server"CommandName="Update"Text="更新"/><br/></ItemTemplate></asp:DataList>
解决方案
解决方案二:
.aspx.vb代码PartialClassnews_Default4InheritsSystem.Web.UI.PageProtectedSubPage_Load(ByValsenderAsObject,ByValeAsSystem.EventArgs)HandlesMe.LoadEndSubProtectedSubDataList1_UpdateCommand(ByValsourceAsObject,_ByValeAsSystem.Web.UI.WebControls.DataListCommandEventArgs)Dimnews_idAsString=_DataList1.DataKeys(e.Item.ItemIndex).ToString()Dimnews_btAsTextBox=_CType(e.Item.FindControl("TextBox1"),TextBox)Dimnews_dateAsTextBox=_CType(e.Item.FindControl("TextBox2"),TextBox)Dimnews_beizhuAsTextBox=_CType(e.Item.FindControl("TextBox3"),TextBox)Dimnews_neirongAsTextBox=_CType(e.Item.FindControl("FreeTextBox1"),TextBox)SqlDataSource1.UpdateParameters("news_id")._DefaultValue=news_idSqlDataSource1.UpdateParameters("news_bt")._DefaultValue=news_bt.TextSqlDataSource1.UpdateParameters("news_date")._DefaultValue=news_date.TextSqlDataSource1.UpdateParameters("news_beizhu")._DefaultValue=news_beizhu.TextSqlDataSource1.UpdateParameters("news_neirong")._DefaultValue=news_neirong.TextSqlDataSource1.Update()DataList1.EditItemIndex=-1DataList1.DataBind()EndSub
解决方案三:
不才懂,坐沙发