Click to See Complete Forum and Search --> : How do i with CheckBoxList put into SQL database, few selected items?


Oktam
08-06-2010, 12:54 PM
Hello,

first at all, sorry, but i`m new in this enviroment, and i`m "stuck" with some problem. If You can help, i thank You advance!

Let see...

I made in SQL - two tables, they are in relationship:

I hope that You can see the image...:confused:
http://img444.imageshack.us/img444/103/sqlrelationship.png

also in web developer i made a form:
http://img38.imageshack.us/img38/7639/formgm.png

So, when i select ONE item, and after i press INSERT BUTTON, i get this particulari value into ML_RLO table.
http://img842.imageshack.us/img842/2016/values.png

BUT - when i select 2 or more item, i also get only ONE value...

So I want, when i selected 2 or more item, and after "INSERT BUTTON" clik, all selected item get in ML_RLO table.

This is how FORM look:

<asp:FormView ID="FormView1" runat="server" DataKeyNames="ID_ML_RLO"
DataSourceID="SqlDataSource1" DefaultMode="Insert">
<EditItemTemplate>
ID_ML_RLO:
<asp:Label ID="ID_ML_RLOLabel1" runat="server"
Text='<%# Eval("ID_ML_RLO") %>' />
<br />
Los:
<asp:TextBox ID="LosTextBox" runat="server" Text='<%# Bind("Los") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
&nbsp;<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Los:
<asp:CheckBoxList ID="CheckBoxList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="ID_ML_Los"
DataValueField="ID_ML_Los" SelectedValue='<%# Bind("Los") %>'>
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
SelectCommand="SELECT [ID_ML_Los] FROM [ML_Los]"></asp:SqlDataSource>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" onclick="InsertButton_Click" />
&nbsp;<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
ID_ML_RLO:
<asp:Label ID="ID_ML_RLOLabel" runat="server" Text='<%# Eval("ID_ML_RLO") %>' />
<br />
Los:
<asp:Label ID="LosLabel" runat="server" Text='<%# Bind("Los") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False"
CommandName="Edit" Text="Edit" />
&nbsp;<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False"
CommandName="Delete" Text="Delete" />
&nbsp;<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:TestConnectionString %>"
DeleteCommand="DELETE FROM [ML_RLO] WHERE [ID_ML_RLO] = @ID_ML_RLO"
InsertCommand="INSERT INTO [ML_RLO] ([Los]) VALUES (@Los)"
SelectCommand="SELECT [ID_ML_RLO], [Los] FROM [ML_RLO]"
UpdateCommand="UPDATE [ML_RLO] SET [Los] = @Los WHERE [ID_ML_RLO] = @ID_ML_RLO">
<DeleteParameters>
<asp:Parameter Name="ID_ML_RLO" Type="Int64" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Los" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Los" Type="String" />
<asp:Parameter Name="ID_ML_RLO" Type="Int64" />
</UpdateParameters>
</asp:SqlDataSource>
</p>

And this is (... i know that there is a PROBLEM, because is not working :o), what i put for initiate loop for inserting few selected item from checkboxlist...

Please dont judge me, because, i`m new...:o

Imports System.Data.SqlClient


Partial Class _Default
Inherits System.Web.UI.Page
Dim CheckBoxList1 As New CheckBoxList


Protected Sub InsertButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim ID_ML_RLO As Integer
For Each OO As ListItem In CheckBoxList1.Items

If OO.Selected = True Then
UL(ID_ML_RLO, OO.Value)
End If

Next


End Sub
Private Sub UL(ByVal ID_ML_RLO As Integer, ByVal Los As String)
Dim OO As String = "INSERT INTO ML_RLO (ID_ML_RLO, Los) Values (@ID_ML_RLO,@Los)"

End Sub

End Class

Also sorry on my bad english... Thank You for all help waht You give me!
:o

yamaharuss
08-07-2010, 07:23 AM
Ask your question in the proper forum. This forum is for classic ASP only.

Oktam
08-07-2010, 07:48 AM
OK, earase my post. Sorry!