私のテキストボックスは1つの値を入力し、同じものを8つ入力します。誰でも知っている理由は?モーダルポップアップのテキストボックスに重複した項目が挿入されます
<li class="item">
<asp:LinkButton ID="FeatureButton" runat="server">Feature</asp:LinkButton>
<asp:Panel ID="FeaturePanel" runat="server" CssClass="modalPopup"
Style="display:none">
<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>
<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>
Protected Sub SubmitFeatures_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles SubmitFeatures.Click
FeatureModal.Hide()
For Each feature As ListItem In cbxAddFeature.Items
If feature.Selected Then
'SQL INSERT: Marketing Table
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"
これは、チェックボックスの挿入も含むモーダルポップアップ全体のコードです。ユーザーに適切なチェックボックスが表示されない場合は、テキストボックスを使用して新しい値を入力できます。
Protected Sub SubmitFeatures_Click(ByVal sender As Object, ByVal e
As System.EventArgs) Handles SubmitFeatures.Click
FeatureModal.Hide()
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
If Not String.IsNullOrEmpty(txtFeature.Text) Then
Dim featureSql As String = "INSERT INTO Feature (FeatureTitle)
VALUES (@FeatureTitle);
INSERT INTO Marketing(ProductID,
MarketingTypeID, MarketingTitle, MarketingData)
VALUES (@ProductID, 3, 'Feature',
scope_identity());
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(featureSql, cn)
cmd.Parameters.Add(New SqlParameter("@FeatureTitle",
txtFeature.Text))
cmd.Parameters.Add(New SqlParameter("@ProductID",
ProductID.Value))
cmd.Parameters.Add(New SqlParameter("@ModifyUser",
System.Web.HttpContext.Current.User.Identity.Name))
cn.Open()
cmd.ExecuteNonQuery()
End Using
cn.Close()
End Using
End If
Next
'keep tab active and redirect to same page
Session("ActiveTabIdx") = TabContainer1.ActiveTabIndex
Response.Redirect(Request.RawUrl)
End Sub
ありがとう! :)完璧に動作します – jlg
@ jlg:私はいくつかの追加提案を追加しました。これはあなたのためのより多くの仕事を意味しますが、それは長期的に報酬を得るでしょう。私はちょうどgoogleのこのコードプロジェクトを見つけた:http://www.codeproject.com/KB/architecture/three_tier_architecture.aspxそれはあなたに私が意味するもののよりよい考えを与えるかもしれません:) – Icarus
良いアイデア。私はすべてのものを聞いたことがあり、次のプロジェクトでそれを試してみます。このサイトは来週にライブになる予定だから、再学習するのに十分な時間があるかどうかはわかりません。それでもやはり大きな障害が1つあります。 :)ありがとう。 – jlg