Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I am getting an error as in "Both DataSource and DataSourceID are defined on 'grdbasetype'. Remove one definition. "

Can ayone solve my problem?

My code is below...

XML
<asp:GridView ID="grdbasetype" runat="server" AutoGenerateColumns="False" Style="width: 100%"
                                                CellPadding="4" ForeColor="#333333" GridLines="None" BorderColor="MidnightBlue"
                                                BorderStyle="Solid" BorderWidth="2px" Font-Names="Verdana" Font-Size="Small"
                                                AllowPaging="true" PageSize="10" OnPageIndexChanging="grdbasetype_PageIndexChanging"
                                                DataKeyNames="basetype" DataSourceID="SqlDataSource1">
                                                <Columns>
                                                    <asp:TemplateField HeaderText="Select">
                                                        <ItemTemplate>
                                                            <asp:CheckBox ID="chkCheck" runat="server" AutoPostBack="true" CausesValidation="False"
                                                                ToolTip='<%# ((GridViewRow)Container).RowIndex + 1%>' />
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:ButtonField HeaderText="Edit" Text="Edit" />
                                                    <asp:ButtonField HeaderText="Delete" Text="Delete" />
                                                    <%--<asp:ButtonField CommandName="Edit" HeaderText="Edit" Text="Edit" />
                                                    <asp:ButtonField CommandName="Update" HeaderText="Update" Text="Update" />
                                                    <asp:ButtonField CommandName="Insert" HeaderText="Insert" Text="Insert" />
                                                    <asp:BoundField DataField="modelname" HeaderText="Model Name" SortExpression="modelname" />
                                                    <asp:BoundField DataField="basetype" HeaderText="Base Type" SortExpression="basetype" />
                                                    <asp:BoundField DataField="description" HeaderText="Description" SortExpression="description" />
                                                    <asp:BoundField DataField="rs" HeaderText="Rupees" SortExpression="rs" />
                                                    <asp:BoundField DataField="euro" HeaderText="Euro" SortExpression="euro" />
                                                    <asp:BoundField DataField="dollar" HeaderText="Dollar" SortExpression="dollar" />
                                                    <asp:BoundField DataField="modelid" HeaderText="Model Id" SortExpression="modelid" />--%>
                                                    <asp:TemplateField HeaderText="Model Name">
                                                        <EditItemTemplate>
                                                            <asp:Label ID="lblModelname" runat="server" Style="text-align: left" Text='<%# Eval("modelname") %>'></asp:Label>
                                                        </EditItemTemplate>
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblModelname" runat="server" Style="text-align: left" Text='<%# Bind("modelname") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Base Type ">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblbasetype" runat="server" Style="text-align: left" Text='<%# Eval("basetype") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Description">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblDescription" runat="server" Style="text-align: left" Text='<%# Eval("description") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Rupees">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblRupees" runat="server" Style="text-align: left" Text='<%# Eval("rs") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Euro">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblEuro" runat="server" Style="text-align: left" Text='<%# Eval("euro") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                    <asp:TemplateField HeaderText="Dollar">
                                                        <ItemTemplate>
                                                            <asp:Label ID="lblDollar" runat="server" Style="text-align: left" Text='<%# Eval("dollar") %>'></asp:Label>
                                                        </ItemTemplate>
                                                    </asp:TemplateField>
                                                </Columns>
                                                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                                <RowStyle BackColor="#EFF3FB" />
                                                <EditRowStyle BackColor="#2461BF" />
                                                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                                                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                                                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                                                <AlternatingRowStyle BackColor="White" />
                                            </asp:GridView>
                                            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:OrionConnectionString %>"
                                                DeleteCommand="DELETE FROM [mbasetype] WHERE [basetype] = @basetype"
                                                UpdateCommand="UPDATE [mbasetype] SET [modelname] = @modelname, [description] = @description ,[rs]=@rs, [euro]=@euro, [dollar]=@dollar WHERE [basetype] = @basetype">
                                                <DeleteParameters>
                                                    <asp:Parameter Name="basetype" Type="String" />
                                                </DeleteParameters>
                                                <UpdateParameters>
                                                    <asp:Parameter Name="modelname" Type="String" />
                                                    <asp:Parameter Name="basetype" Type="String" />
                                                    <asp:Parameter Name="description" Type="String" />
                                                    <asp:Parameter Name="rs" Type="Double" />
                                                    <asp:Parameter Name="dollar" Type="Double" />
                                                    <asp:Parameter Name="euro" Type="Double" />
                                                    <asp:Parameter Name="modelid" Type="String" />
                                                </UpdateParameters>
                                            </asp:SqlDataSource>


Thanking in advance..
Swapnil
Posted
Updated 26-May-10 1:58am
v2

Swapnil 2009 wrote:
I am getting an error as in "Both DataSource and DataSourceID are defined on 'grdbasetype'. Remove one definition. "


Error message itself is self explanatory.Use either DataSource or DataSourceID.
 
Share this answer
 
v2
Actually Mr Jecob if I remove Data source Id then How can I edit the rows in my datagrid??

there should be some connection between gridview and sqldatasource where I have written code for update and delete..can you explain this??
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900