我如何在向导控件上执行 DirectCast 到 sql?
How I do DirectCast on Wizard Control to sql?
我尝试使用向导控件,我的向导有 5 步。我想在用户点击完成按钮时存储我的数据,但我在将数据存储到 sql 时遇到了一些问题。这是我的代码:
<asp:SqlDataSource ID="Wizard1SDS"
runat="server"
ConnectionString="<%$ ConnectionStrings:tr9DbConn %>"
InsertCommand = "INSERT INTO [tr9_detail_eval] ([response_text]) VALUES (@txb_answer1)">
<InsertParameters>
<asp:ControlParameter Name="txb_answer1" Type="String" ControlID="txb_answer1" PropertyName="Text"/>
</InsertParameters>
</asp:SqlDataSource>
我背后的代码:
Protected Sub Wizard1_FinishButtonClick(sender As Object, e As WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
Dim Wizard1SDS As SqlDataSource = DirectCast(Me.Wizard1.WizardSteps(0).FindControl("Wizard1SDS"), SqlDataSource)
Wizard1SDS.Insert()
End Sub
我的向导文本框代码:
<div style="margin : 10px;">
<asp:TextBox runat="server" ID="txb_answer1" TextMode="MultiLine" Columns="10" Rows="50" Height="123px" Width="600px" CssClass="step1" />
</div>
有什么建议吗?谢谢,
我已经用后面的代码解决了我的问题,我将 DirectCast 替换为 CType,并将文本框转换为字符串,然后找到控件文本框。这是我的代码:
Protected Sub Wizard1_FinishButtonClick(sender As Object, e As WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
Dim txb_answer1 As String = CType(Me.Wizard1.WizardSteps(0).FindControl("txb_answer1"), TextBox).Text
Wizard1SDS.Insert()
Response.Redirect("Eval.aspx")
End Sub
我尝试使用向导控件,我的向导有 5 步。我想在用户点击完成按钮时存储我的数据,但我在将数据存储到 sql 时遇到了一些问题。这是我的代码:
<asp:SqlDataSource ID="Wizard1SDS"
runat="server"
ConnectionString="<%$ ConnectionStrings:tr9DbConn %>"
InsertCommand = "INSERT INTO [tr9_detail_eval] ([response_text]) VALUES (@txb_answer1)">
<InsertParameters>
<asp:ControlParameter Name="txb_answer1" Type="String" ControlID="txb_answer1" PropertyName="Text"/>
</InsertParameters>
</asp:SqlDataSource>
我背后的代码:
Protected Sub Wizard1_FinishButtonClick(sender As Object, e As WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
Dim Wizard1SDS As SqlDataSource = DirectCast(Me.Wizard1.WizardSteps(0).FindControl("Wizard1SDS"), SqlDataSource)
Wizard1SDS.Insert()
End Sub
我的向导文本框代码:
<div style="margin : 10px;">
<asp:TextBox runat="server" ID="txb_answer1" TextMode="MultiLine" Columns="10" Rows="50" Height="123px" Width="600px" CssClass="step1" />
</div>
有什么建议吗?谢谢,
我已经用后面的代码解决了我的问题,我将 DirectCast 替换为 CType,并将文本框转换为字符串,然后找到控件文本框。这是我的代码:
Protected Sub Wizard1_FinishButtonClick(sender As Object, e As WizardNavigationEventArgs) Handles Wizard1.FinishButtonClick
Dim txb_answer1 As String = CType(Me.Wizard1.WizardSteps(0).FindControl("txb_answer1"), TextBox).Text
Wizard1SDS.Insert()
Response.Redirect("Eval.aspx")
End Sub