insert dynamic data from datalist into database

Intelext

New Member
I am using visual studio and c# to create a staff rota system where staff member's names from the "Staff" table are displayed in a datalist. As well as this, I have created 2 dropdown lists in asp, separate from the "Staff" table, although they appear in the item template tag to enable them to be dynamically created next to the staff names. The user can then select the staff's shift start and end times from the dropdowns.I decided to use a datalist and dynamic dropdowns as the Staff table will frequently be updated as new staff may start or leave, therefore rota's in the future may contain different numbers of staff.\[code\] <table class="style57" width="100%"> <tr> <td class="style70" width="100%"> <asp:DataList ID="DataList1" runat="server" DataSourceID="StaffHours" ShowFooter="False" Width="668px" Height="16px" CellPadding="1" CellSpacing="1""> <ItemTemplate> <table width="100%"> <tr> <td class="style76" width="0%"> <asp:Label ID="lblStaffID" runat="server" bgcolor="#CCCCCC" Visible=false Text='<%# Eval("StaffID") %>'/> </td> <td class="style73" width="20%"> <asp:Label ID="lblFirstName" runat="server" bgcolor="#CCCCCC" Text='<%# Eval("FirstName") %>'/> &nbsp;<asp:Label ID="lblLastName" runat="server" bgcolor="#CCCCCC" Text='<%# Eval("LastName") %>' /> </td> <td width="10%"> <asp:DropDownList ID="ddStartShift" runat="Server"> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/Start Time" Selected="True"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/06:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/07:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/08:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/09:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/10:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/11:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/12:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/13:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/14:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/15:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/16:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/17:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/18:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/19:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/20:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/21:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/22:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/23:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/00:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/01:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/02:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/03:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/04:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/05:00"></asp:ListItem> </asp:DropDownList> </td> <td width="10%"> <asp:DropDownList ID="ddEndShift" runat="Server"> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/End Time" Selected="True"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/06:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/07:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/08:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/09:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/10:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/11:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/12:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/13:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/14:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/15:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/16:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/17:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/18:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/19:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/20:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/21:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/22:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/23:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/00:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/01:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/02:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/03:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/04:00"></asp:ListItem> <asp:ListItem Value="http://stackoverflow.com/questions/15555200/05:00"></asp:ListItem> </asp:DropDownList> </td> </tr> </table> </ItemTemplate> </asp:DataList> <asp:SqlDataSource ID="StaffHours" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="SELECT [StaffID], [FirstName], [LastName] FROM [Staff]"> </asp:SqlDataSource> </td> </tr></table>\[/code\]As these dropdowns are dynamically created in the datalist, I cannot figure out how to insert their values for each staff member into the "Rota" table as they are not identified therefore I cannot enter them into a parameter for a stored procedure.
 
Back
Top