0

I have this source code below where by I have a gridview and on edit/ add a formview appears as a popup. My problem is that the insert and edit are not working. Any ideas on how to fix this problem??

<cc1:ToolkitScriptManager ID="ScriptManager1" runat="server"></cc1:ToolkitScriptManager>

    <asp:Panel ID="newpnl" style="display:none;background:#F0F0F0;" runat="server">
        <div style="position:absolute; top:-10px; right:-15px;"><asp:ImageButton ImageUrl="images/close.png" ID="btn_close" runat="server" Width="20px" /></div>
        <asp:Label ID="lblid" runat="server" Text='<%# Eval("id") %>'
                        Visible="False"></asp:Label>
                        <asp:FormView ID="FormView1" runat="server" DataKeyNames="id"
                            DataSourceID="SqlDataSource1" DefaultMode="Insert"
                          Width="100%">
                            <InsertItemTemplate>
                                <table >


                                    <tr>
                                        <td >
                                             Name:</td>
                                        <td>
                                            <asp:TextBox ID="txtname" runat="server"
                                                Text='<%# Bind("name") %>'  />
                                        </td>
                                    </tr>


                                    <tr>
                                        <td align="center" colspan="2">
                                            <asp:Button ID="InsertButton" runat="server" CausesValidation="True"
                                                CommandName="Insert" Text="Insert"  />
                                             <asp:Button ID="InsertCancelButton" runat="server"
                                                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                                        </td>
                                    </tr>
                                </table>
                            </InsertItemTemplate>
                        </asp:FormView>
                           </asp:Panel>

                           <asp:HyperLink ID="HyperLink1" runat="server">Add Person</asp:HyperLink>
    <cc1:ModalPopupExtender ID="HyperLink1_ModalPopupExtender" runat="server"
        DynamicServicePath="" Enabled="True" CancelControlID="btn_close" TargetControlID="HyperLink1" PopupControlID="newpnl">
    </cc1:ModalPopupExtender>
    <br />
    <asp:GridView ID="gridview1" runat="server" EnableModelValidation="True"
        AutoGenerateColumns="False" Width="1050px" AllowPaging="True"
        EmptyDataText="No record created" AllowSorting="True"
        DataKeyNames="id" DataSourceID="SqlDataSource1">
 <Columns>

            <asp:BoundField DataField="name"  HeaderText="Name"
                SortExpression="name" >
                <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                </asp:BoundField>

                <asp:TemplateField ShowHeader="False">
                <ItemTemplate>
                    <asp:Button ID="LinkButton1" runat="server" CausesValidation="False"
                        Text="Edit"></asp:Button>
                          <cc1:ModalPopupExtender ID="LinkButton1_ModalPopupExtender" runat="server"
                        DynamicServicePath="" CancelControlID="btn_close" Enabled="True" PopupControlID="pnledit" TargetControlID="LinkButton1">
                    </cc1:ModalPopupExtender>
                       <asp:panel ID="pnledit" style="display:none;" runat="server">
        <div style="position:absolute; top:-10px; right:-15px;"><asp:ImageButton ImageUrl="images/close.png" ID="btn_close" runat="server" Width="20px" /></div>

                    <asp:panel ID="pnledit1" runat="server" BackColor="White" Width="600px" BorderColor="#F0F0F0" BorderStyle="Solid" BorderWidth="4px">
                      <asp:Label ID="lblid" runat="server" Text='<%# Eval("id") %>'
                        Visible="False"></asp:Label>
                        <asp:FormView ID="FormView2" runat="server" DataKeyNames="id"
                            DataSourceID="SqlDataSource3" DefaultMode="Edit"
                             Width="100%">
                            <EditItemTemplate>
                                <table >

                                  <tr>
                                        <td >
                                             Name:</td>
                                        <td>
                                        <asp:TextBox ID="txtname" runat="server"  Text='<%#Bind("name") %>'></asp:TextBox>
                                        </td>
                                        </tr>

                                    <tr>
                                        <td align="center" colspan="2">
                                            <asp:Button ID="UpdateButton" runat="server" CausesValidation="True"
                                                CommandName="Update" Text="Update" />
                                             <asp:Button ID="UpdateCancelButton" runat="server"
                                                CausesValidation="False" CommandName="Cancel" Text="Cancel" />
                                        </td>
                                    </tr>
                                </table>
                            </editItemTemplate>
                        </asp:FormView>
</asp:panel>
</asp:panel>  <asp:SqlDataSource ID="SqlDataSource3" runat="server"
        ConnectionString="<%$ ConnectionStrings:DataConection %>"
  SelectCommand="SELECT * from [Person] where [id]=@id"
        UpdateCommand="UPDATE person SET [name] = @name WHERE [id] = @id">
         <SelectParameters>
         <asp:ControlParameter Name="id" Type="Int32" ControlID="lblid" PropertyName="Text" />
         </SelectParameters>
         <UpdateParameters>
         <asp:Parameter Name="name" Type="String" />

            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>
</asp:SqlDataSource>
                    <asp:Button ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
                        OnClientClick="return confirm('Are you sure that you want to delete this record?')"
                        Text="Delete"></asp:Button>
                </ItemTemplate>
                <ItemStyle Width="100px" HorizontalAlign="Center" />
            </asp:TemplateField>
 </Columns>
     <HeaderStyle BorderStyle="None" Font-Bold="True" Font-Size="Medium"
         ForeColor="#34496B" />
 </asp:GridView>
             <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:DataConection %>"

                SelectCommand="SELECT * FROM [Person] order by id "
                DeleteCommand="DELETE FROM [Person] WHERE [id] = @id"
                InsertCommand="INSERT INTO [Person] ([name]) VALUES (@name)"
        UpdateCommand="UPDATE [Person] SET [name] = @name WHERE [id] = @id"
                >
                 <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <InsertParameters>
            <asp:Parameter Name="name" Type="String" />



        </InsertParameters>
        <UpdateParameters>
         <asp:Parameter Name="name" Type="String" />

            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>

        </asp:SqlDataSource>
1
Contributor
1
Reply
2
Views
4 Years
Discussion Span
Last Post by vipmo
0

after some testing I found out that sqldatasource stopped from inserting/updating. How can I fix the problem?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.