asp:DetailsView插入不触发

时间:2014-01-23 11:45:08

标签: asp.net detailsview

我有下面的代码,由于某种原因,插入查询没有触发将信息添加到SQL数据库中。

我认为是由于页面上的类型所致。但不确定。任何想法为什么它不解雇和保存

 <asp:DetailsView ID="DetailsView1" runat="server" 
    AutoGenerateInsertButton="True" AutoGenerateRows="False" 
    DataSourceID="sqlQuestion" DefaultMode="Insert" 
    Height="50px" Width="450px" CellPadding="4" ForeColor="#4B6C9E" 
    DataKeyNames="questionID">
        <AlternatingRowStyle BackColor="White" />
        <CommandRowStyle BackColor="#D1DDF1"  />
        <EditRowStyle BackColor="#F1F1F2"  />
        <FieldHeaderStyle BackColor="#546E96"  ForeColor="White" Width="100px" 
            BorderColor="#465767" />
        <Fields>


            <asp:BoundField DataField="questionID" HeaderText="questionID" 
            InsertVisible="False" SortExpression="questionID" ReadOnly="True" 
                Visible="False" />



            <asp:TemplateField HeaderText="QuestionNo" SortExpression="QuestionNo">
            <InsertItemTemplate>
                    <asp:ListBox ID="ListBox2" runat="server" 
                        DataSourceID="SqlAvailableQuestionNumbers" DataTextField="questionno" 
                        DataValueField="questionno" Rows="1" 
                        SelectedValue='<%# Bind("QuestionNo") %>' Width="50px">
                    </asp:ListBox>
                    <asp:SqlDataSource ID="SqlAvailableQuestionNumbers" runat="server" 
                        ConnectionString="<%$ ConnectionStrings:testConnectionString %>" SelectCommand="select questionno from tblQuestionNumbers
where questionno not in
(select questionno from tblquestions where subjectid = @subjectid)">
                        <SelectParameters>
                            <asp:QueryStringParameter Name="subjectid" QueryStringField="subjectid" />
                        </SelectParameters>
                    </asp:SqlDataSource>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("QuestionNo") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>


            <asp:TemplateField HeaderText="QuestionType" SortExpression="QuestionType">
            <InsertItemTemplate>
                    <asp:ListBox ID="ListBox3" runat="server" DataSourceID="LinqGetQuestionTypes" 
                        DataTextField="name" DataValueField="questionTypeID" Rows="1" 
                        SelectedValue='<%# Bind("QuestionType") %>'></asp:ListBox>
                    <asp:LinqDataSource ID="LinqGetQuestionTypes" runat="server" 
                        ContextTypeName="DataClassesDataContext" EntityTypeName="" 
                        TableName="QuestionTypes">
                    </asp:LinqDataSource>
                </InsertItemTemplate>
            </asp:TemplateField>


            <asp:TemplateField HeaderText="question" SortExpression="question">
             <EditItemTemplate>
                    <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("question") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Rows="3" 
                        Text='<%# Bind("question") %>' TextMode="MultiLine"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label4" runat="server" Text='<%# Bind("question") %>'></asp:Label>
                </ItemTemplate>
                <ControlStyle BorderStyle="Inset" Height="50px" Width="800px" />
            </asp:TemplateField>


            <asp:BoundField DataField="A" HeaderText="A" SortExpression="A" 
                ControlStyle-Width="20px" ControlStyle-BorderStyle=Inset >
            <ControlStyle BorderStyle="Inset" Width="500px" />
            <ItemStyle Width="500px" />
            </asp:BoundField>


            <asp:BoundField DataField="B" HeaderText="B" 
            SortExpression="B" ControlStyle-Width="20px" ControlStyle-BorderStyle=Inset >
            <ControlStyle BorderStyle="Inset" Width="500px" />
            </asp:BoundField>

            <asp:BoundField DataField="C" HeaderText="C" 
            SortExpression="C" ControlStyle-Width="20px" ControlStyle-BorderStyle=Inset >
            <ControlStyle BorderStyle="Inset" Width="500px" />
            </asp:BoundField>

            <asp:BoundField DataField="D" HeaderText="D" 
            SortExpression="D" ControlStyle-Width="20px" ControlStyle-BorderStyle=Inset >
            <ControlStyle Width="500px" />
            </asp:BoundField>


            <asp:TemplateField HeaderText="correctAnswer" SortExpression="correctAnswer">
            <EditItemTemplate>
                    <asp:ListBox ID="ListBox1" runat="server" Rows="1" 
                        SelectedValue='<%# Bind("correctAnswer") %>'>
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                        <asp:ListItem>D</asp:ListItem>
                    </asp:ListBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:ListBox ID="ListBox1" runat="server" Rows="1" 
                        SelectedValue='<%# Bind("correctAnswer") %>'>
                        <asp:ListItem>A</asp:ListItem>
                        <asp:ListItem>B</asp:ListItem>
                        <asp:ListItem>C</asp:ListItem>
                        <asp:ListItem>D</asp:ListItem>
                    </asp:ListBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("correctAnswer") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>

            <asp:BoundField DataField="explanation" HeaderText="explanation" 
                SortExpression="explanation" />

            <asp:BoundField DataField="bookRef" HeaderText="bookRef" 
                SortExpression="bookRef" />
            <asp:BoundField DataField="sectionID" HeaderText="sectionID" 
                SortExpression="sectionID" Visible="False" />
            <asp:BoundField DataField="syllabusRef" HeaderText="syllabusRef" 
                SortExpression="syllabusRef" ReadOnly="True" Visible="False" />
            <asp:BoundField DataField="noChapSec" HeaderText="noChapSec" 
                SortExpression="noChapSec" ReadOnly="True" Visible="False" />
            <asp:TemplateField HeaderText="subjectID" SortExpression="subjectID">
            <EditItemTemplate>
                    <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("subjectID") %>'></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox ID="TextBox4" runat="server" 
                        Text='<%# request.querystring("subjectID") %>' CssClass="editRowSmall" 
                        ReadOnly="True" Width="50px"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("subjectID") %>'></asp:Label>
                </ItemTemplate>

            </asp:TemplateField>
        </Fields>
        <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#507CD1" />
    </asp:DetailsView>
    <asp:SqlDataSource ID="sqlQuestion" runat="server" 
        ConnectionString="<%$ ConnectionStrings:testConnectionString %>" 
        InsertCommand="INSERT INTO tblQuestions(QuestionType, QuestionNo, question, A, B, C, D, correctAnswer, explanation, bookRef,  subjectID) VALUES (@QuestionType, @QuestionNo, @question, @A, @B, @C, @D , @correctAnswer, @explanation, @bookRef,  @subjectID)" 


        SelectCommand="SELECT questionID, QuestionType, QuestionNo, question, A, B, C, D, correctAnswer, explanation, bookRef, sectionID, subjectID, syllabusRef, noChapSec FROM tblQuestions WHERE (subjectID = @subjectID)">
        <InsertParameters>
            <asp:Parameter Name="QuestionType" type="Int32"/>
            <asp:Parameter Name="QuestionNo" type="Int32"/>
            <asp:Parameter Name="question" type="String"/>
            <asp:Parameter Name="A" type="String"/>
            <asp:Parameter Name="B" type="String"/>
            <asp:Parameter Name="C" type="String"/>
            <asp:Parameter Name="D" type="String"/>
            <asp:Parameter Name="correctAnswer" type="char"/>
            <asp:Parameter Name="explanation" type="String"/>
            <asp:Parameter Name="bookref" type="String"/>
            <asp:QuerystringParameter Name="subjectID" QueryStringField="subjectid" type="Int32"/>
        </InsertParameters>
        <SelectParameters>
            <asp:QueryStringParameter Name="subjectID" QueryStringField="subjectid" 
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    <asp:DropShadowExtender ID="DetailsView1_DropShadowExtender" runat="server" 
        Enabled="True" TargetControlID="DetailsView1">
    </asp:DropShadowExtender>

0 个答案:

没有答案