I'm working on a laptop ordering system in asp.net 2 (vb) as as part of this when they have selected a computer they can then select a set of options from a generated list. ie for a laptop they can order specific
mouse
keyboard
memory
etc.
I originally generated a datalist with a tick box next to each item which they tick and the press an add options button at the bottom to add. The customer wants them to be able to add a quantity though instead of just as a tickbox just 1. What was suggested is you have
item description quantity [x]
item description quantity [x]
item description quantity [ ]
What I want to do is have quantity disabled if the tickbox is unticked, but enabled (ie they can edit it) if the tickbox is ticked.
I figure a dataview is probably the best option for doing this, though i'm not too familiar with it, but cannot see how I can set it to do this on a tickbox - Iv'e only succeeded so far with using a datagrid and buttons rather than tickboxes. ie you click the edit quantity button the quantity field is enabled.
The code for the datgrid I did is below, but I gather datgrids are no longers used in asp.net2, I don't want to update the data in the database (merely pass it to the shopping cart) so there is no update.
<form id="frmOptions" method="post" runat="server">
<asp:datagrid id="dgOptions" runat="server" DataKeyField="ID" CellPadding="4" CellSpacing="0" BackColor="White"
BorderWidth="1px" BorderStyle="None" BorderColor="#DEDFDE" AutoGenerateColumns="False" PageSize="6"
AllowPaging="False" GridLines="Vertical" ForeColor="Black">
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#DFCF49"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#ECE5A2"></AlternatingItemStyle>
<ItemStyle CssClass="barlight" BackColor="#F4F3D7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#810000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="txtDescription" ReadOnly="True" HeaderText="Title">
<HeaderStyle Width="2000px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:LinkButton Width="10px" Runat="server" CommandName="EditQuantity" Text='<%# DataBinder.Eval(Container, "DataItem.iDefaultQuantity") %>' ID="Linkbutton1">
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EditQuantity" runat="server" Width="60" Text='<%# DataBinder.Eval(Container, "DataItem.iDefaultQuantity") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" EditText="Edit Quantity" />
</Columns>
</asp:datagrid>
</form>
and the code behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
dgOptions.EditItemIndex = -1
End If
End Sub
Private Sub BindGrid()
Dim Options As New MiddleTier.CatalogueDB
dgOptions.DataSource = Options.GetRelatedOptionsList(5)
dgOptions.DataBind()
End Sub
Private Sub dgOptions_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOptions.PageIndexChanged
dgOptions.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
' This creates a javascript which puts focus on the textbox passed to it
Private Sub createFocusScript(ByVal textBox As TextBox)
ClientScript.RegisterStartupScript(Me.GetType(), "focus", "<script language=""JavaScript"">" & vbCrLf & _
vbTab & "frmOptions." & textBox.ClientID & ".focus();" & _
vbCrLf & vbTab & "frmOptions." & textBox.ClientID & ".select();" & _
vbCrLf & "<" & "/script>")
End Sub
Private Sub dgOptions_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgOptions.ItemCommand
Select Case e.CommandName
' This is on tick the box
Case "EditQuantity", "Edit"
dgOptions.EditItemIndex = e.Item.ItemIndex
BindGrid()
createFocusScript(dgOptions.Items(e.Item.ItemIndex).Cells(2).FindControl("EditQuantity"))
' This will be untick box
Case "Cancel"
dgOptions.EditItemIndex = -1
BindGrid()
End Select
End Sub
mouse
keyboard
memory
etc.
I originally generated a datalist with a tick box next to each item which they tick and the press an add options button at the bottom to add. The customer wants them to be able to add a quantity though instead of just as a tickbox just 1. What was suggested is you have
item description quantity [x]
item description quantity [x]
item description quantity [ ]
What I want to do is have quantity disabled if the tickbox is unticked, but enabled (ie they can edit it) if the tickbox is ticked.
I figure a dataview is probably the best option for doing this, though i'm not too familiar with it, but cannot see how I can set it to do this on a tickbox - Iv'e only succeeded so far with using a datagrid and buttons rather than tickboxes. ie you click the edit quantity button the quantity field is enabled.
The code for the datgrid I did is below, but I gather datgrids are no longers used in asp.net2, I don't want to update the data in the database (merely pass it to the shopping cart) so there is no update.
<form id="frmOptions" method="post" runat="server">
<asp:datagrid id="dgOptions" runat="server" DataKeyField="ID" CellPadding="4" CellSpacing="0" BackColor="White"
BorderWidth="1px" BorderStyle="None" BorderColor="#DEDFDE" AutoGenerateColumns="False" PageSize="6"
AllowPaging="False" GridLines="Vertical" ForeColor="Black">
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#DFCF49"></SelectedItemStyle>
<AlternatingItemStyle BackColor="#ECE5A2"></AlternatingItemStyle>
<ItemStyle CssClass="barlight" BackColor="#F4F3D7"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#810000"></HeaderStyle>
<Columns>
<asp:BoundColumn DataField="txtDescription" ReadOnly="True" HeaderText="Title">
<HeaderStyle Width="2000px"></HeaderStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="Quantity">
<ItemTemplate>
<asp:LinkButton Width="10px" Runat="server" CommandName="EditQuantity" Text='<%# DataBinder.Eval(Container, "DataItem.iDefaultQuantity") %>' ID="Linkbutton1">
</asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="EditQuantity" runat="server" Width="60" Text='<%# DataBinder.Eval(Container, "DataItem.iDefaultQuantity") %>'>
</asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="PushButton" CancelText="Cancel" EditText="Edit Quantity" />
</Columns>
</asp:datagrid>
</form>
and the code behind
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindGrid()
dgOptions.EditItemIndex = -1
End If
End Sub
Private Sub BindGrid()
Dim Options As New MiddleTier.CatalogueDB
dgOptions.DataSource = Options.GetRelatedOptionsList(5)
dgOptions.DataBind()
End Sub
Private Sub dgOptions_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEventArgs) Handles dgOptions.PageIndexChanged
dgOptions.CurrentPageIndex = e.NewPageIndex
BindGrid()
End Sub
' This creates a javascript which puts focus on the textbox passed to it
Private Sub createFocusScript(ByVal textBox As TextBox)
ClientScript.RegisterStartupScript(Me.GetType(), "focus", "<script language=""JavaScript"">" & vbCrLf & _
vbTab & "frmOptions." & textBox.ClientID & ".focus();" & _
vbCrLf & vbTab & "frmOptions." & textBox.ClientID & ".select();" & _
vbCrLf & "<" & "/script>")
End Sub
Private Sub dgOptions_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgOptions.ItemCommand
Select Case e.CommandName
' This is on tick the box
Case "EditQuantity", "Edit"
dgOptions.EditItemIndex = e.Item.ItemIndex
BindGrid()
createFocusScript(dgOptions.Items(e.Item.ItemIndex).Cells(2).FindControl("EditQuantity"))
' This will be untick box
Case "Cancel"
dgOptions.EditItemIndex = -1
BindGrid()
End Select
End Sub