嵌套gridview的问题

时间:2013-08-21 06:44:52

标签: c# asp.net gridview

我正在尝试使用插入更新和删除在gridview内部设计gridview,但在此我无法插入记录。任何人都可以帮忙吗?

这是数据库表

1) tbl_SShow(ShowTimeId{P-Auto inc.},TheatreId,MovieId,FromDate,ToDate)
2) tbl_Show(ShowID{P-Auto inc.},ShowTime,Silver,Gold, Platinum,ShowTimeId) 
3) tbl_Theatre(TheatreId{P-Auto inc.}, TName, Taddress)

这是aspx页面

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <script language=javascript type="text/javascript">
        function expandcollapse(obj,row)
        {
            var div = document.getElementById(obj);
            var img = document.getElementById('img' + obj);

            if (div.style.display == "none")
            {
                div.style.display = "block";
                if (row == 'alt')
                {
                    img.src = "minus.gif";
                }
                else
                {
                    img.src = "minus.gif";
                }
                img.alt = "Close to view other Customers";
            }
            else
            {
                div.style.display = "none";
                if (row == 'alt')
                {
                    img.src = "plus.gif";
                }
                else
                {
                    img.src = "plus.gif";
                }
                img.alt = "Expand to show Orders";
            }
        } 
        </script>
    </head>
    <body>

            <form id="AddEventForm" runat="server">
                           <ul id="tabsmenu1" class="tabsmenu">
                                <li class="active"><a href="#tab2">Add Show Time</a></li>
                            </ul>

                                <div class="form">
                                    <asp:GridView ID="GridView1" runat="server" AllowPaging="True" BackColor="#f1f1f1" 
                                        AutoGenerateColumns=false DataSourceID="SqlDataSource1" DataKeyNames="MovieID" 
                                        GridLines=None OnRowDataBound="GridView1_RowDataBound" 
                                        OnRowCommand = "GridView1_RowCommand" OnRowUpdating = "GridView1_RowUpdating" BorderStyle=Outset
                                        OnRowDeleting = "GridView1_RowDeleting" OnRowDeleted = "GridView1_RowDeleted"
                                        OnRowUpdated = "GridView1_RowUpdated" AllowSorting=true
                                        Width="80%" >
                                        <RowStyle BackColor="Gainsboro" />
                                        <AlternatingRowStyle BackColor="White" />
                                        <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
                                        <FooterStyle BackColor="White" />
                                        <Columns>
                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <a href="javascript:expandcollapse('div<%# Eval("ShowTimeId") %>', 'one');">
                                                        <img id="imgdiv<%# Eval("ShowTimeId") %>" alt="Click to show/hide Orders for Customer <%# Eval("ShowTimeId") %>"  width="9px" border="0" src="../images/plus.gif"/>
                                                    </a>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:Label ID="lblShowTimeId" Text='<%# Eval("ShowTimeId") %>' runat="server"></asp:Label>
                                                </EditItemTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Theatre Id" SortExpression="TheatreId">
                                                <ItemTemplate>
                                                    <asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:Label ID="lblTheatreId" Text='<%# Eval("TheatreId") %>' runat="server"></asp:Label>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:DropDownList ID="ddlTheatre" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="1">
                                                    </asp:DropDownList>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="Movie Id" SortExpression="MovieId">
                                                <ItemTemplate><%# Eval("MovieId")%></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
                                                    </asp:DropDownList>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:DropDownList ID="ddlMovie" runat="server" CssClass="form_input" AutoPostBack="True" TabIndex="2">
                                                    </asp:DropDownList>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="From Date" SortExpression="FromDate">
                                                <ItemTemplate><%# Eval("FromDate")%></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtFromDate" Text='<%# Eval("FromDate") %>' runat="server"></asp:TextBox>
                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                                                    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
                                                    </asp:CalendarExtender>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtFromDate" Text='' runat="server"></asp:TextBox>
                                                    <asp:ImageButton ID="ImageButton1" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                                                    <asp:CalendarExtender ID="CalendarExtender1" runat="server" TargetControlID="txtFromDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton1">
                                                    </asp:CalendarExtender>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="To Date" SortExpression="ToDate">
                                                <ItemTemplate><%# Eval("ToDate")%></ItemTemplate>
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="txtToDate" Text='<%# Eval("ToDate") %>' runat="server"></asp:TextBox>
                                                    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                                                    <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
                                                    </asp:CalendarExtender>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    <asp:TextBox ID="txtToDate" Text='' runat="server"></asp:TextBox>
                                                    <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/cal/calendar.gif" AlternateText="Click to show calendar" TabIndex="3" />
                                                    <asp:CalendarExtender ID="CalendarExtender2" runat="server" TargetControlID="txtToDate" Format="dd/MM/yyyy" PopupButtonID="ImageButton2">
                                                    </asp:CalendarExtender>
                                                </FooterTemplate>
                                            </asp:TemplateField>
                                            <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                                            <asp:TemplateField HeaderText="Delete">
                                                <ItemTemplate>
                                                    <asp:LinkButton ID="linkDeleteShow" CommandName="Delete" runat="server">Delete</asp:LinkButton>
                                                </ItemTemplate>
                                                <FooterTemplate>
                                                    <asp:LinkButton ID="linkAddShow" CommandName="AddShow" runat="server">Add</asp:LinkButton>
                                                </FooterTemplate>
                                            </asp:TemplateField>

                                            <asp:TemplateField>
                                                <ItemTemplate>
                                                    <tr>
                                                        <td colspan="100%">
                                                            <div id="div<%# Eval("ShowTimeId") %>" style="display:none;position:relative;left:15px;OVERFLOW: auto;WIDTH:97%" >

                                                            <asp:GridView ID="GridView2" AllowPaging="True" AllowSorting="true" BackColor="White" Width=100% Font-Size=X-Small
                                                                AutoGenerateColumns="false" Font-Names="Verdana" DataKeyNames="ShowTimeId" runat="server" ShowFooter="true" 
                                                                OnPageIndexChanging="GridView2_PageIndexChanging" OnRowUpdating = "GridView2_RowUpdating" CssClass="Gridview" 
                                                                OnRowCommand = "GridView2_RowCommand" OnRowEditing = "GridView2_RowEditing" GridLines=None
                                                                OnRowUpdated = "GridView2_RowUpdated" OnRowCancelingEdit = "GridView2_CancelingEdit" OnRowDataBound = "GridView2_RowDataBound"
                                                                OnRowDeleting = "GridView2_RowDeleting" OnRowDeleted = "GridView2_RowDeleted" OnSorting = "GridView2_Sorting"
                                                                BorderStyle=Double BorderColor="#0083C1">
                                                            <RowStyle BackColor="Gainsboro" />
                                                            <AlternatingRowStyle BackColor="White" />
                                                            <HeaderStyle BackColor="#0083C1" ForeColor="White"/>
                                                            <FooterStyle BackColor="White" />
                                                            <Columns>
                                                            <asp:TemplateField HeaderText="Show ID" SortExpression="ShowID">
                                                                <ItemTemplate>
                                                                    <asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
                                                                </ItemTemplate>
                                                                <EditItemTemplate>
                                                                    <asp:Label ID="lblShowID" Text='<%# Eval("ShowID") %>' runat="server"></asp:Label>
                                                                </EditItemTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField HeaderText="ShowTime" SortExpression="ShowTime">
                                                                <ItemTemplate><%# Eval("ShowTime")%></ItemTemplate>
                                                                <EditItemTemplate>
                                                                    <asp:TextBox ID="txtShowTime" Text='<%# Eval("ShowTime")%>' runat="server"></asp:TextBox>
                                                                </EditItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:TextBox ID="txtShowTime" Text='' runat="server"></asp:TextBox>
                                                                </FooterTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField HeaderText="Silver" SortExpression="Silver">
                                                                <ItemTemplate><%# Eval("Silver")%></ItemTemplate>
                                                                <EditItemTemplate>
                                                                    <asp:TextBox ID="txtSilver" Text='<%# Eval("Silver")%>' runat="server"></asp:TextBox>
                                                                </EditItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:TextBox ID="txtSilver" Text='' runat="server"></asp:TextBox>
                                                                </FooterTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField HeaderText="Gold" SortExpression="Gold">
                                                                <ItemTemplate><%# Eval("Gold")%></ItemTemplate>
                                                                <EditItemTemplate>
                                                                    <asp:TextBox ID="txtGold" Text='<%# Eval("Gold")%>' runat="server"></asp:TextBox>
                                                                </EditItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:TextBox ID="txtGold" Text='' runat="server"></asp:TextBox>
                                                                </FooterTemplate>
                                                            </asp:TemplateField>
                                                            <asp:TemplateField HeaderText="Platinum" SortExpression="Platinum">
                                                                <ItemTemplate><%# Eval("Platinum")%></ItemTemplate>
                                                                <EditItemTemplate>
                                                                    <asp:TextBox ID="txtPlatinum" Text='<%# Eval("Platinum")%>' runat="server"></asp:TextBox>
                                                                </EditItemTemplate>
                                                                <FooterTemplate>
                                                                    <asp:TextBox ID="txtPlatinum" Text='' runat="server"></asp:TextBox>
                                                                </FooterTemplate>
                                                            </asp:TemplateField>
                                                            <asp:CommandField HeaderText="Edit" ShowEditButton="True" />
                                                            <asp:TemplateField HeaderText="Delete">
                                                                 <ItemTemplate>
                                                                    <asp:LinkButton ID="linkDeleteCust" CommandName="Delete" runat="server">Delete</asp:LinkButton>
                                                                 </ItemTemplate>
                                                                 <FooterTemplate>
                                                                    <asp:LinkButton ID="linkAddOrder" CommandName="AddShow" runat="server">Add</asp:LinkButton>
                                                                 </FooterTemplate>
                                                            </asp:TemplateField>
                                                            </Columns>
                                                            </asp:GridView>
                                                            </div>
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                            </asp:TemplateField>
                                        </Columns>
                                    </asp:GridView>

                                    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                                        ConnectionString="<%$ ConnectionStrings:Event_MovieConnectionString %>" 
                                        SelectCommand="SELECT s.[ShowTimeId], s.[TheatreId], s.[MovieId], s.[FromDate], s.[ToDate], s.[Created], 
                                        s.[Modified] FROM [tbl_SShow] s ORDER BY s.[ShowTimeId]">
                                    </asp:SqlDataSource>
                               </div>
            </form>

    </body>
    </html>

请给我一个解决方案

感谢。

0 个答案:

没有答案