misnstt
asked on
Limit Selection to 5 Items in Asp DataList
I have a ASP DataList which allows the user to select a item then once selected there is a second button to insert it into the Database.
I want to limit the user to only be able to select up to 5 items that re displayed in the DataList. I don't know how to do this. Please Help. Thanks.
I want to limit the user to only be able to select up to 5 items that re displayed in the DataList. I don't know how to do this. Please Help. Thanks.
<asp:DataList ID="DataList3" runat="server" OnEditCommand="DataList3_EditCommand" DataKeyField="cuisineid" DataSourceID="SqlDataSource1" RepeatColumns="7" RepeatDirection="Horizontal" GridLines="Vertical">
<ItemTemplate>
<asp:Panel ID="Panel1" runat="server" Visible="False">
<asp:Label ID="cuisinenameLabel" runat="server" Text='<%# Eval("cuisinename") %>' />
<asp:Label ID="imageLabel" runat="server" Text='<%# Eval("image") %>' />
</asp:Panel>
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-link" Text = '<%# Eval("cuisinename") %>' CommandName ="Edit" ></asp:LinkButton>
</ItemTemplate>
</asp:DataList>
the button that does the inserting into the database should keep a running count of how many items have been selected, then when it reaches 5 (it would do the check every time the button that does the selection is pressed) it can either disable itself or display a message that max amount of items have been selected
ASKER
Hello yes that is a great method however im not sure how to do that either .
can you post the code for the button that does the selection as well as the save button?
ASKER
Hello here is the Select Button:
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-link" Text = '<%# Eval("cuisinename") %>' CommandName ="Edit" ></asp:LinkButton>
Here is the Insert Button Code:
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim SQL As String = ""
' Insert a new record
Dim connectionString As String = ConfigurationManager.Conne ctionStrin gs("dbMyCM SConnectio nString"). Connection String
Dim insertSql As String = "INSERT INTO [chefscuisine] ([UserId], [cuisinetype], [image]) VALUES (@UserId, @cuisinetype, @image)"
Using myConnection As New SqlConnection(connectionSt ring)
myConnection.Open()
Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWi thValue("U serId", UserId.Text.Trim())
myCommand.Parameters.AddWi thValue("@ cuisinetyp e", TextBox2.Text.Trim())
myCommand.Parameters.AddWi thValue("@ image", TextBox3.Text.Trim())
myCommand.ExecuteNonQuery( )
myConnection.Close()
'UserId.Text = String.Empty
TextBox2.Text = String.Empty
TextBox3.Text = String.Empty
DataList2.DataBind()
'SqlDataSource2.DataBind()
Panel2.Visible = False
End Using
End Sub
<asp:LinkButton ID="LinkButton2" runat="server" CssClass="btn btn-link" Text = '<%# Eval("cuisinename") %>' CommandName ="Edit" ></asp:LinkButton>
Here is the Insert Button Code:
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim SQL As String = ""
' Insert a new record
Dim connectionString As String = ConfigurationManager.Conne
Dim insertSql As String = "INSERT INTO [chefscuisine] ([UserId], [cuisinetype], [image]) VALUES (@UserId, @cuisinetype, @image)"
Using myConnection As New SqlConnection(connectionSt
myConnection.Open()
Dim myCommand As New SqlCommand(insertSql, myConnection)
myCommand.Parameters.AddWi
myCommand.Parameters.AddWi
myCommand.Parameters.AddWi
myCommand.ExecuteNonQuery(
myConnection.Close()
'UserId.Text = String.Empty
TextBox2.Text = String.Empty
TextBox3.Text = String.Empty
DataList2.DataBind()
'SqlDataSource2.DataBind()
Panel2.Visible = False
End Using
End Sub
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You