2011-11-14 4 views
1

管理者は、特定の製品に機能を追加するためのさまざまなチェックボックスから選択できるモーダルポップアップがあります。管理者が利用できるはずのチェックボックスがあるが、その機能がデータベースにないためではないと思われる場合は、ユーザーが製品に新しい機能を追加できるようにテキストボックスを追加しました。モーダルポップアップにテキストボックスを追加するとINSERTが許可されなくなりました

テキストボックスを追加すると、挿入が許可されなくなりました。最初はそれが各ループのチェックボックスとして同じであったが、私は最近それを変更して、テキストボックスが各ループごとに独自のものになるようにした。私が言う言葉txtFeature.Text下に下線を持ってValue of type 'Char' cannot be converted to 'System.Web.UI.WebControl.Textbox.'

VBコード:

For Each feature As ListItem In cbxAddFeature.Items 
     If feature.Selected Then 

      Dim strSQL As String = "INSERT INTO Marketing 
            (ProductID, MarketingTypeID, MarketingTitle, 
            MarketingData) 
            VALUES (@ProductID, 3, 'Feature', @MarketingData); 
            UPDATE Product SET ModifyDate = getdate(), 
            ModifyUser = @ModifyUser 
            WHERE ProductID = @ProductID" 

      Using cn As New SqlConnection 
      (System.Configuration.ConfigurationManager.ConnectionStrings 
      ("LocalSqlServer").ConnectionString) 

       Using cmd As New SqlCommand(strSQL, cn) 

        cmd.Parameters.Add(New SqlParameter("@ProductID", ProductID.Value)) 
        cmd.Parameters.Add(New SqlParameter("@MarketingData", 
        feature.Value)) 
        cmd.Parameters.Add(New SqlParameter("@ModifyUser", 
        System.Web.HttpContext.Current.User.Identity.Name)) 

        cn.Open() 

        cmd.ExecuteNonQuery() 
       End Using 

       cn.Close() 
      End Using 
     Else 
     End If 
    Next 
    For Each txtFeature As TextBox In txtFeature.Text 
     If txtFeature.Text Then 
      Dim featureSql As String = "INSERT INTO Marketing(ProductID, 
             MarketingTypeID, MarketingTitle, MarketingData) 
             VALUES (@ProductID, 3, 'Feature', 
             @MarketingData); 
             UPDATE Product SET ModifyDate = getdate(), 
             ModifyUser = @ModifyUser 
             WHERE ProductID = @ProductID; 
             INSERT INTO Feature (FeatureTitle) 
             VALUES (@FeatureTitle)" 

      Using cn As New SqlConnection 
      (System.Configuration.ConfigurationManager.ConnectionStrings 
      ("LocalSqlServer").ConnectionString) 

       Using cmd As New SqlCommand(featureSql, cn) 

        cmd.Parameters.Add(New SqlParameter("@FeatureTitle", 
             txtFeature.Text)) 

        cn.Open() 

        cmd.ExecuteNonQuery() 
       End Using 

       cn.Close() 
      End Using 
     End If 

ASPX:

<div class="PopupHeader">Add a Feature</div> 
      <asp:CheckBoxList ID="cbxAddFeature" runat="server" 
      DataSourceID="dsNewFeatures" DataTextField="FeatureTitle" 
      DataValueField="FeatureID"></asp:CheckBoxList> 
      New Feature:<asp:TextBox ID="txtFeature" runat="server"></asp:TextBox> 
      <asp:Label ID="FeatureError" runat="server" ></asp:Label><br /> 
      <asp:Button ID="SubmitFeatures" runat="server" Text="Submit" /> 
      <asp:Button ID="CancelSubmitFeatures" runat="server" Text="Cancel" /> 
     </asp:Panel> 
     <asp:ModalPopupExtender ID="FeatureModal" runat="server" 
     BackgroundCssClass="modalBackground" CancelControlID="CancelSubmitFeatures" 
     DropShadow="True" DynamicServicePath="" Enabled="True" 
     PopupControlID="FeaturePanel" TargetControlID="FeatureButton"> 
     </asp:ModalPopupExtender> 
+0

チェックボックスが必要なときに表示されない問題に取り組んでいるようです。回避策の問題は、通常、図面ボードを再訪して問題の原因になることを意味します。 – HardCode

+0

チェックボックスは問題ではありません。モーダルポップアップは、テキストボックスを追加する前に完全に機能しました。テキストボックスが問題です。私はそれを明確にしなかった場合は申し訳ありません。 – jlg

答えて

1

あなたは文字列を反復処理し、その中に各文字をキャストしようとしていますテキストボックスクラス:For Each txtFeature As TextBox In txtFeature.Text。明らかにエラーが発生しました。そのサイクルを削除して、代わりにtxtFeature.Textのプロパティをチェックしてください:If Not String.IsNullOrEmpty(txtFeature.Text) Then ...

+0

これは役立ちます。ありがとうございました。 – jlg

+0

よろしくお願いします:) –

関連する問題