我有一個DropDownList
和ListBox
運行良好。當用戶將Products
表中的所選內容移動到ListBox
中的ProductsMail
表時,我需要能夠將所選值從DropDownList
插入到數據庫中。我試圖多次修改SQL字符串,但沒有成功,例如"+EmailDDN.SelectedItem+"
和"+EmailDDN.SelectedValue+"
等。我可以將所選值顯示在EmailLabel1
標籤中,但不在查詢中。請提供解決方案。 我很感謝你的時間。 _ JT將單個C#下拉選擇的值傳遞給查詢字符串
嗨suryakiran,
在 「DestinationDataSource」:
UpdateCommand="UPDATE ProductsMail SET Name = @Name, Email = @Email, EmailID = @EmailID WHERE ID = @ID".
我試圖修改,如:
"UPDATE ProductsMail SET Name = @Name, Email = ' + @Email + ', EmailID = @EmailID WHERE ID = @ID" and "UPDATE ProductsMail SET Name = @Name, Email = ' +EmailDDN.SelectedItem+ ', EmailID = @EmailID WHERE ID = @ID"
和其他人,但沒有成功。
<telerik:RadScriptManager ID="ScriptManager" runat="server" />
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel1" LoadingPanelID="RadAjaxLoadingPanel1">
<asp:SqlDataSource ID="SqlDataSource2" ConnectionString="<%$ ConnectionStrings:IPdataConnectionString %>"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT DISTINCT Email FROM [aspnet_Membership]"
runat="server"></asp:SqlDataSource>
<label for="EmailDDN">
<asp:Label ID="Label2" runat="server" class="text">Select Email: </asp:Label>
</label>
<asp:DropDownList ID="EmailDDN" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource2"
AppendDataBoundItems="True" DataTextField="Email" DataValueField="Email" OnSelectedIndexChanged="DDN_SelectedIndexChanged">
<asp:ListItem>
Select your email address
</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<asp:Label ID="EmailLabel1" runat="server" />
<br />
<br />
<br />
</telerik:RadAjaxPanel>
<telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel2" />
<telerik:RadAjaxPanel runat="server" ID="RadAjaxPanel2" LoadingPanelID="RadAjaxLoadingPanel1">
<telerik:RadListBox runat="server" ID="RadListBox1" DataSourceID="SourceDataSource"
AllowAutomaticUpdates="true" DataKeyField="ID" DataTextField="Name" DataSortField="SortOrder"
Width="230px" Height="200px" AllowTransfer="true" TransferToID="RadListBox2" TransferMode="Copy"
AutoPostBackOnTransfer="true" />
<telerik:RadListBox runat="server" ID="RadListBox2" DataSourceID="DestinationDataSource"
AllowAutomaticUpdates="true" DataKeyField="ID" DataTextField="Name" DataSortField="SortOrder"
Width="230px" Height="200px" AllowReorder="true" AutoPostBackOnReorder="true" AllowDelete="True"
AutoPostBackOnDelete="true" />
</telerik:RadAjaxPanel>
<asp:SqlDataSource ID="SourceDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:IPdataConnectionString %>"
ProviderName="System.Data.SqlClient" DeleteCommand="DELETE FROM Products WHERE ID = @ID"
InsertCommand="INSERT INTO Products (Name, ID, Email, EmailID) VALUES (@Name, @ID, @Email, @EmailID)"
SelectCommand="SELECT Name, ID, Email FROM Products" UpdateCommand="UPDATE Products SET Name = @Name, Email = @Email, EmailID = @EmailID WHERE ID = @ID">
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="EmailID" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="EmailID" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="EmailDDN" DefaultValue="Select One" Name="Email"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="DestinationDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:IPdataConnectionString %>"
ProviderName="System.Data.SqlClient" DeleteCommand="DELETE FROM ProductsMail WHERE ID = @ID"
InsertCommand="INSERT INTO ProductsMail (Name, ID, Email, EmailID) VALUES (@Name, @ID, @Email, @EmailID)"
SelectCommand="SELECT Name, ID, Email FROM ProductsMail" UpdateCommand="UPDATE ProductsMail SET Name = @Name, Email = @Email, EmailID = @EmailID WHERE ID = @ID">
<UpdateParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="EmailID" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="EmailID" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="EmailDDN" DefaultValue="Select One" Name="Email"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
============================================
============================================
protected void DDN_SelectedIndexChanged(System.Object sender, System.EventArgs e)
{
EmailLabel1.Text = EmailDDN.SelectedItem.ToString();
}
您可以在那裏定義sql數據源並在select-change上更新電子郵件標籤,但是您實際上在哪裏調用數據庫更新? – Frater
上面的回覆.... –