locked
query with form view RRS feed

  • Question

  • User-707211747 posted

    i have an access database and i want to connect an query with this form view

    i mean thats my access data source is not table is query the problem is when i want  in CONFIGURE DATA SOURCE to choice  ADVANCE TAB and the GENERATE INSERT ,UPDATE AND DELETE STATEMENT is not active does that mean i can insert update and delete when i use the query >

    then  whats advice me in this case what should be i do?

    Saturday, July 17, 2010 7:35 PM

Answers

  • User-1802908944 posted

    this is working code. check where are you wrong...


    <asp:FormView ID="fvCountry" runat="server" DataKeyNames="Country_Id" DataSourceID="ds_Country"
                                        Width="100%" AllowPaging="True" Height="78px">
                                        <EditItemTemplate>
                                            <table style="width: 400px; height: 95px;">
                                                <tr>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        Country Id:</td>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        <asp:Label ID="Country_IdLabel1" runat="server" Text='<%# Eval("Country_Id") %>' CssClass="ItemTemplate"></asp:Label></td>
                                                </tr>
                                                <tr>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        Country:
                                                        <img src="icons_small/required.jpg" /></td>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' MaxLength="255" CssClass="textcss" Width="200px"></asp:TextBox><asp:RequiredFieldValidator ID="rfvCountry" runat="server" ControlToValidate="CountryTextBox" ErrorMessage="Country Required." SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        <asp:ValidationSummary ID="ValidationSummary2" runat="server" Width="167px" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid;
                                                        border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left">
                                                        Note:
                                                        <img src="icons_small/required.jpg" />
                                                        symbol is for Required Field.</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: center;">
                                                        &nbsp;
                                                        <asp:Button ID="btnUpdate" runat="server" CommandName="Update"
                                                            CssClass="btncss" Text="Update" /><asp:Button ID="btnCancel" runat="server" CausesValidation="False"
                                                                CommandName="Cancel" CssClass="btncss" Text="Cancel" /></td>
                                                </tr>
                                            </table>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                            <table style="width: 400px; height: 126px;">
                                                <tr>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        Country
                                                        Id:</td>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        <asp:TextBox ID="Country_IdTextBox" runat="server" Text='[Auto Generated]' MaxLength="3" BackColor="#E0E0E0" BorderStyle="Solid" BorderWidth="1px" Enabled="False" CssClass="textcss" Width="97px"></asp:TextBox></td>
                                                </tr>
                                                <tr>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        Country:
                                                        <img src="icons_small/required.jpg" /></td>
                                                    <td style="text-align: left; border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid;">
                                                        <asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' MaxLength="255" CssClass="textcss" Width="216px"></asp:TextBox><asp:RequiredFieldValidator ID="rfvCountry" runat="server" ControlToValidate="CountryTextBox" ErrorMessage="Country Required." SetFocusOnError="True">*</asp:RequiredFieldValidator></td>
                                                </tr>
                                                <tr>
                                                    <td align="left" colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left">
                                                        <asp:ValidationSummary ID="ValidationSummary2" runat="server" />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td align="left" colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid;
                                                        border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left">
                                                        Note:
                                                        <img src="icons_small/required.jpg" />
                                                        symbol is for Required Field.</td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: center;">
                                                        &nbsp;
                                                        <asp:Button ID="btnInsert" runat="server" CommandName="Insert" CssClass="btncss"
                                                            Text="Insert" /><asp:Button ID="btnCancel" runat="server" CommandName="Cancel" CssClass="btncss"
                                                            Text="Cancel" CausesValidation="False" /></td>
                                                </tr>
                                            </table>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <table style="width: 400px; height: 79px;">
                                                <tr>
                                                    <td align="left" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left;" id="TD1" runat="server">
                                                        Country Id:
                                                    </td>
                                                    <td align="left" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left;">
                                                        <asp:Label ID="Country_IdLabel" runat="server" Text='<%# Eval("Country_Id") %>' CssClass="ItemTemplate"></asp:Label></td>
                                                </tr>
                                                <tr>
                                                    <td align="left" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left;">
                                                        Country:</td>
                                                    <td align="left" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: left;">
                                                        <asp:Label ID="CountryLabel" runat="server" Text='<%# Bind("Country") %>' CssClass="ItemTemplate" Width="177pt"></asp:Label></td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2" style="border-right: #ffcccc 1pt solid; border-top: #ffcccc 1pt solid; border-left: #ffcccc 1pt solid; border-bottom: #ffcccc 1pt solid; text-align: center;">
                                                        &nbsp;
                                                        <asp:Button ID="btnEdit" runat="server" CommandName="Edit" CssClass="btncss" Text="Edit" CausesValidation="False" /><asp:Button
                                                            ID="btnDelete" runat="server" CommandName="Delete" CssClass="btncss" Text="Delete" CausesValidation="False" /><asp:Button
                                                                ID="btnNew" runat="server" CommandName="NEw" CssClass="btncss" Text="New" CausesValidation="False" /></td>
                                                </tr>
                                            </table>
                                        </ItemTemplate>
                                        <PagerSettings Mode="NextPreviousFirstLast" FirstPageText="First" LastPageText="Last" NextPageText="Next" PreviousPageText="Prev" />
                                        <PagerStyle BackColor="SeaShell" BorderColor="Red" BorderStyle="Solid" BorderWidth="1px" />
                                    </asp:FormView>
                                    <asp:SqlDataSource ID="ds_Country" runat="server" ConflictDetection="CompareAllValues"
                                        ConnectionString="<%$ ConnectionStrings:dbCIMSConnectionString %>" DeleteCommand="DELETE FROM [tblCountryMaster] WHERE [Country_Id] = @original_Country_Id AND [Country] = @original_Country"
                                        InsertCommand="INSERT INTO [tblCountryMaster] ( [Country]) VALUES (@Country)"
                                        OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [Country_Id], [Country] FROM [tblCountryMaster] order by [Country_Id]"
                                        UpdateCommand="UPDATE [tblCountryMaster] SET [Country] = @Country WHERE [Country_Id] = @original_Country_Id AND [Country] = @original_Country">
                                        <DeleteParameters>
                                            <asp:Parameter Name="original_Country_Id" Type="Int32" />
                                            <asp:Parameter Name="original_Country" Type="String" />
                                        </DeleteParameters>
                                        <UpdateParameters>
                                            <asp:Parameter Name="Country" Type="String" />
                                            <asp:Parameter Name="original_Country_Id" Type="Int32" />
                                            <asp:Parameter Name="original_Country" Type="String" />
                                        </UpdateParameters>
                                        <InsertParameters>
                                            <asp:Parameter Name="Country" Type="String" />
                                        </InsertParameters>
                                    </asp:SqlDataSource>


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, July 18, 2010 12:29 AM