已答复 DetailsView updaten

  • Sonntag, 26. Dezember 2010 13:32
     
     

    Hallo,

    meine Seite wird von einer Masterseite abgeleitet. In meiner Seite ist ein View enthalten, der wiederum einen DetailsView enthalt. Der DetailsView soll bearbeitet werden. Für das Bearbeiten habe ich einige Felder des DetailsView in TemplateFelder umgewandelt und für das bearbeiten DropDown (Kategorie, Format) Elemente eingefügt. Die DropDowns sind an einen SQLDataSource gebunden, das SelectedValue-Attribut ist an die entsprechende Spalte des DataSource gebunden. Das Update des DetailsView soll mit einer Stored Procedure gemacht werden. Das Update klappt für die Textfelder des DetailsView, jedoch werden die neuen Werte aus der Auswahl der DropDown nicht in die DB geschrieben. In der Stored Procedure ist das Update vorgesehen. In HTML Quelltext werden die DropDowns richtig dargestellt. Fehlermeldung o.ä. gibts keine. Ich weiß wirklich nicht mehr weiter...Hat jemand einen Tipp für mich?

    Danke, Axel

    <asp:MultiView
            id="MultiView1"
            ActiveViewIndex="0"
            Runat="server">
            (...)
            <asp:View ID="View2" runat="server">
                <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateEditButton="True"
                    AutoGenerateInsertButton="True" AutoGenerateRows="False" CellPadding="4"
                    DataKeyNames="DocId,IndexId,CatId,FormatId" DataSourceID="SqlDataSource4"
                    ForeColor="#333333" GridLines="None" Height="50px" Width="125px">
                    <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
                    <CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
                    <EditRowStyle BackColor="#999999" />
                    <FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
                    <Fields>
                        <asp:TemplateField HeaderText="Titel" SortExpression="DocTitel">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DocTitel") %>'></asp:TextBox>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:Label ID="Label2" runat="server" Text='<%# Eval("DocTitel") %>'></asp:Label>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("DocTitel") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        (...)
                        <asp:TemplateField HeaderText="Kategorie" SortExpression="CatName">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList3" runat="server"
                                    DataSourceID="SqlDataSource10" DataTextField="CatName"
                                    DataValueField="CatId" SelectedValue='<%# Bind("CatId") %>'>
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource10" runat="server"
                                    ConnectionString="<%$ ConnectionStrings:DocumentsDBConnectionString %>"
                                    SelectCommand="SELECT [CatId], [CatName], [CatRank] FROM [Category] WHERE ([ProjId] = @ProjId) ORDER BY [CatRank]">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="ProjId" SessionField="ProjId" Type="Object" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("CatName") %>'></asp:TextBox>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label6" runat="server" Text='<%# Bind("CatName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                        <asp:TemplateField HeaderText="Format" SortExpression="FormatName">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList4" runat="server"
                                    DataSourceID="SqlDataSource11" DataTextField="FormatName"
                                    DataValueField="FormatId" SelectedValue='<%# Bind("FormatId") %>'>
                                </asp:DropDownList>
                                <asp:SqlDataSource ID="SqlDataSource11" runat="server"
                                    ConnectionString="<%$ ConnectionStrings:DocumentsDBConnectionString %>"
                                    SelectCommand="SELECT [FormatId], [FormatName], [FormatRank] FROM [DocFormat] WHERE ([ProjId] = @ProjId) ORDER BY [FormatRank]">
                                    <SelectParameters>
                                        <asp:SessionParameter Name="ProjId" SessionField="ProjId" Type="Object" />
                                    </SelectParameters>
                                </asp:SqlDataSource>
                            </EditItemTemplate>
                            <InsertItemTemplate>
                                <asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("FormatName") %>'></asp:TextBox>
                            </InsertItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label7" runat="server" Text='<%# Bind("FormatName") %>'></asp:Label>
                            </ItemTemplate>
                        </asp:TemplateField>
                       
                        <asp:BoundField DataField="DocId" HeaderText="DocId" SortExpression="DocId"
                            Visible="False" />
                        <asp:BoundField DataField="IndexId" HeaderText="IndexId"
                            SortExpression="IndexId" Visible="False" />
                        <asp:BoundField DataField="FormatId" HeaderText="FormatId"
                            SortExpression="FormatId" Visible="False" />
                        <asp:BoundField DataField="CatId" HeaderText="CatId" SortExpression="CatId"
                            Visible="False" />
                    </Fields>
                    <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
                    <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
                </asp:DetailsView>
                <asp:SqlDataSource ID="SqlDataSource4" runat="server"
                    ConnectionString="<%$ ConnectionStrings:DocumentsDBConnectionString %>"
                    onupdated="SqlDataSource4_Updated"
                    SelectCommand="SELECT [DocTitel], [DocDescr], [DocId], [FormatName], [CatName], [IndexName], [IndexDate], [UserLastname], [IndexCreated], [StatusName], [FormatId], [StatusId], [CatId], [IndexId], [IndexDescr] FROM [vw_lastDocuments] WHERE ([IndexId] = @IndexId)"
                    UpdateCommand="sp_updateDoc_DocIndex" UpdateCommandType="StoredProcedure">
                    <SelectParameters>
                        <asp:SessionParameter Name="IndexId" SessionField="IndexId" Type="Object" />
                    </SelectParameters>
                    <UpdateParameters>
                        <asp:Parameter Name="DocId" DbType="Guid" />
                        <asp:Parameter Name="DocTitel" Type="String" />
                        <asp:Parameter Name="DocDescr" Type="String" />
                        <asp:Parameter Name="CatId" DbType="Guid" />
                        <asp:Parameter Name="FormatId" DbType="Guid" />
                        <asp:Parameter Name="IndexId" DbType="Guid" />
                        <asp:Parameter Name="IndexName" Type="String" />
                        <asp:Parameter Name="IndexDescr" Type="String" />
                    </UpdateParameters>
                </asp:SqlDataSource>
                <br />
            </asp:View>

     

    Stored Procedure:

     

    (...)

     


        UPDATE       [Document]
        SET                DocTitel = @DocTitel, DocDescr = @DocDescr, CatId = @CatId, FormatId = @FormatId
        WHERE        (DocId = @DocId)

        UPDATE       DocIndex
        SET                IndexName = @IndexName, IndexDescr = @IndexDescr
        WHERE        (IndexId = @IndexId)

Alle Antworten

  • Montag, 27. Dezember 2010 13:48
     
     Beantwortet

    Hallo,

     

    ich habe die Lösung gefunden. Für die Dropdowns muss man <asp:controlparameter> benutzen.

     

    <UpdateParameters>
                        <asp:Parameter Name="DocId" DbType="Guid" />
                        <asp:Parameter Name="DocTitel" Type="String" />
                        <asp:Parameter Name="DocDescr" Type="String" />
                        <asp:Parameter Name="IndexId" DbType="Guid" />
                        <asp:Parameter Name="IndexName" Type="String" />
                        <asp:Parameter Name="IndexDescr" Type="String" />
                        <asp:ControlParameter name="FormatId" controlid="DetailsView1$DropDownList4" propertyname="SelectedValue" />
                        <asp:ControlParameter name="CatId" controlid="DetailsView1$DropDownList3" propertyname="SelectedValue" />
                    </UpdateParameters>

     

    Axel

    • Als Antwort markiert fonzie1860 Montag, 27. Dezember 2010 13:48
    •