Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gettign error Both DataSource and DataSourceID are defined on 'GridView2'. Remove one definition.

Status
Not open for further replies.

leo57

Programmer
Oct 28, 2013
33
US
Both DataSource and DataSourceID are defined on 'GridView2'. Remove one definition.
this grid was using a SQL datasource adn I removed it and am using a unbound
sometimes it works fine then other times I get the above message. maybe someone can tell me what still left over to make this error?

HTML
Code:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <p style="font-size: large">
        Add New Recognition: Welcome 
        <asp:Label ID="lblName" runat="server" Text="."></asp:Label>
        </p>
    <p>
        Enter Empl Given
        <asp:TextBox ID="txtFindGivenName" runat="server" Width="100px"></asp:TextBox>
&nbsp;&nbsp; Surname 
        <asp:TextBox ID="txtFindSurName" runat="server" Width="100px"></asp:TextBox>
    &nbsp; 
        <asp:Button ID="btnFindEmployee" runat="server" Text="Find Employee" 
            Width="129px" />
    &nbsp;
        <asp:Button ID="btnReset" runat="server" Text="Reset" Visible="False" />
&nbsp;&nbsp;<asp:TextBox ID="txtEnterpriseID" runat="server" Width="107px" 
            Visible="False"></asp:TextBox>
&nbsp;<br />Note: Entering a letter or two for either name will show all matches in the 
        grid.
        <asp:Label ID="lblYellowhightedDoNotChoose" runat="server" BackColor="Yellow" 
            BorderColor="Black" BorderStyle="Solid" 
            style="color: #FF0000; font-weight: 700" 
            Text=" &quot;Yellow Highlighted rows are NON-employees. Please do not choose.&quot;" 
            Visible="False" Height="27px"></asp:Label>
        <br />
        <asp:Label ID="lblSelectEmployee" runat="server" Font-Bold="True" 
            ForeColor="Black" Text="Select Employee"></asp:Label>
    
                <asp:GridView ID="GridView3" runat="server" BackColor="#CCCCCC" 
                        BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" CellPadding="4" AllowSorting="True"
                        CellSpacing="2" ForeColor="Black">
                    <Columns>
                        <asp:CommandField ButtonType="Button" ShowCancelButton="False" 
                            ShowSelectButton="True" />
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>

    </p>
    <p>
        <asp:Label ID="lblEmployeeData" runat="server" Text="Employee Data" 
            style="font-weight: 700; color: #000000"></asp:Label>
        <asp:GridView ID="GridView4" runat="server" BackColor="White" 
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" 
            CellSpacing="1" GridLines="None">
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#594B9C" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#33276A" />
        </asp:GridView>
</p>

  
    <p>
        Enter Nominator Gvn
        <asp:TextBox ID="txtFindNominatorGivenName" runat="server" Width="100px"></asp:TextBox>
&nbsp; Surname
        <asp:TextBox ID="txtFindNominatorSurName" runat="server" Width="100px"></asp:TextBox>
&nbsp; 
        <asp:Button ID="btnFindNominator" runat="server" Text="Find Nominator" 
            Width="129px" />
        &nbsp;&nbsp;<asp:TextBox ID="txtNominatorEnterpriseID" runat="server" 
            Width="107px" TextMode="Password" Visible="False"></asp:TextBox>
        <br />
        <asp:Label ID="lblYellowhightedDoNotChoose0" runat="server" BackColor="Yellow" 
            BorderColor="Black" BorderStyle="Solid" 
            style="color: #FF0000; font-weight: 700" 
            Text=" &quot;Yellow Highlighted rows are NON-employees. Please do not choose.&quot;" 
            Visible="False" Height="27px"></asp:Label>
    
                <asp:GridView ID="GridView6" runat="server" BackColor="#CCCCCC" 
                        BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
            CellPadding="4" AllowSorting="True"
                        CellSpacing="2" ForeColor="Black" style="margin-top: 10px">
                    <Columns>
                        <asp:CommandField ButtonType="Button" ShowCancelButton="False" 
                            ShowSelectButton="True" />
                    </Columns>
                    <FooterStyle BackColor="#CCCCCC" />
                    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" />
                    <RowStyle BackColor="White" />
                    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#808080" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#383838" />
                </asp:GridView>


  
        <span class="style1"><strong>Nominator Name</strong></span>
        &nbsp;
        <asp:GridView ID="GridView5" runat="server" BackColor="White" 
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" 
            CellSpacing="1" GridLines="None">
            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#594B9C" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#33276A" />
        </asp:GridView>
        </p>
    <p>
        <asp:Label ID="lblDate" runat="server" Text="Enter Recognition Date" 
            style="font-weight: 700; color: #000000"></asp:Label>
&nbsp;
        <asp:Button ID="btnToday" runat="server" Text="Today" />
&nbsp;<asp:TextBox ID="txtRecognitionDate" runat="server" Width="145px"></asp:TextBox>
&nbsp;<asp:Button ID="btnShowCalendar" runat="server" Text="Calendar" Width="88px" />
&nbsp;
        &nbsp;<asp:Calendar ID="Calendar1" runat="server" Height="50px" Visible="False" 
            Width="285px" SelectedDate="09/16/2013 13:52:09"></asp:Calendar>
    </p>
    <p>
        <asp:Label ID="lblAwardType" runat="server" Text="Choose Award Type" 
            style="font-weight: 700; color: #000000"></asp:Label>
&nbsp;
        <asp:DropDownList ID="ddlAwardTypes" runat="server" Height="22px" Width="190px">
        </asp:DropDownList>
&nbsp;&nbsp;<asp:Button ID="btnAddEditAwards" runat="server" Text="Add/Edit Awards" 
            Width="139px" />
        <br />
        <asp:Label ID="Label1" runat="server" style="font-weight: 700; color: #000000" 
            Text="Event&nbsp;"></asp:Label>
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
        <asp:TextBox ID="txtEvent" runat="server" Width="194px"></asp:TextBox>
&nbsp;<br />
        <asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Black" 
            Text="Awarded"></asp:Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <asp:DropDownList ID="ddlAwardedYN" runat="server" 
            Width="78px">
            <asp:ListItem>Y</asp:ListItem>
            <asp:ListItem>N</asp:ListItem>
        </asp:DropDownList>
        <br /><span class="style1"><strong>Summary</strong></span>
        <asp:TextBox ID="txtSummary" runat="server" Height="92px" TextMode="MultiLine" 
            Width="509px"></asp:TextBox>
    </p>
    
<asp:Button ID="btnAddNew" runat="server" Text="Add New" Width="91px" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <asp:Button ID="btnReset2" runat="server" 
            Font-Size="Large" Height="30px" 
    Text="Reset" Width="120px" style="margin-top: 6px" />
        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;


        <!------------------------------ SQLdatasource ------------------------>


<!-------------------------- Grid view at bottom ------------------------->

    <asp:GridView ID="GridView2" runat="server" BackColor="White" 
            CssClass="RowStyle" 
            BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" 
            CellSpacing="1" GridLines="None" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" 
            >

            <Columns>
                
               
      <asp:CommandField ButtonType="Button" ShowSelectButton="True" 
                SelectText="Edit"/>
                
               
                <asp:BoundField DataField="EmployeeName" HeaderText="EmployeeName" 
                    SortExpression="EmployeeName" />
                <asp:BoundField DataField="EmplEPriseID" HeaderText="EmplEPriseID" 
                    SortExpression="EmplEPriseID" />
                <asp:BoundField DataField="Location" HeaderText="Location" 
                    SortExpression="Location" />
                <asp:BoundField DataField="VPName" HeaderText="VPName" 
                    SortExpression="VPName" />
                <asp:BoundField DataField="Nominator" HeaderText="Nominator" 
                    SortExpression="Nominator" />
                <asp:BoundField DataField="ReportToManager" HeaderText="ReportToManager" 
                    SortExpression="ReportToManager" />
                <asp:BoundField DataField="Report1" HeaderText="Report1" 
                    SortExpression="Report1" />
                <asp:BoundField DataField="Report2" HeaderText="Report2" 
                    SortExpression="Report2" />
                <asp:BoundField DataField="Report3" HeaderText="Report3" 
                    SortExpression="Report3" />
                <asp:BoundField DataField="AwardType" HeaderText="AwardType" 
                    SortExpression="AwardType" />
                <asp:BoundField DataField="DateAwarded" HeaderText="DateAwarded" 
                    SortExpression="DateAwarded" />
                <asp:BoundField DataField="Event" HeaderText="Event" 
                    SortExpression="Event" />
                <asp:BoundField DataField="Awarded" HeaderText="Awarded" 
                    SortExpression="Awarded" >
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:BoundField DataField="NominationSummary" HeaderText="NominationSummary" 
                    SortExpression="NominationSummary" />
                <asp:BoundField DataField="UserEpriseID" HeaderText="UserEpriseID" 
                    SortExpression="UserEpriseID" />
                <asp:BoundField DataField="UniqueID" HeaderText="UniqueID" 
                    SortExpression="UniqueID" InsertVisible="False" ReadOnly="True" >
                <ItemStyle HorizontalAlign="Center" />
                </asp:BoundField>
                <asp:CommandField ButtonType="Button" ShowDeleteButton="True" />
            </Columns>

            <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
            <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
            <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
            <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
            <SortedAscendingCellStyle BackColor="#F1F1F1" />
            <SortedAscendingHeaderStyle BackColor="#594B9C" />
            <SortedDescendingCellStyle BackColor="#CAC9C9" />
            <SortedDescendingHeaderStyle BackColor="#33276A" />

        </asp:GridView>
    </asp:Content>

VBA code with DataSource
Code:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        Dim connStr As String = gblConnectionString
            
        ' fill bottom main grid with data
        Dim SQLString As String

        SQLString = "SELECT UniqueID, CommonName as EmployeeName, EmployeeEpriseID as EmplEPriseID, Location, VPName, Nominator, " & _
                        "ReportToManager, Report1, Report2, Report3, AwardType,  convert (nvarchar(12),DateAwarded,101) as DateAwarded, Event, Awarded, " & _
                        "Left(NominationSummary,100) + '... (Click Edit button <--- to see all)' as NominationSummary, ePrizeID as UserEpriseID FROM Recognition " & _
                        "Where ePrizeID = '" & Session("ePrizeID") & "' " & _
                        "Order by UniqueID DESC"

        GridView2.DataSource = PopulateGridwithSQL(SQLString)
        GridView2.DataBind()

     End Sub

 Public Function PopulateGridwithSQL(ByVal SQLStatement As String) As DataTable

         Dim Conn As SqlConnection
        Dim connStr As String = gblConnectionString

        Conn = New SqlConnection(connStr)
        Conn.Open()

        Dim daTrans As New SqlDataAdapter
        Dim dtTrans As New DataTable

        Try

            daTrans.SelectCommand = New SqlCommand(SQLStatement, Conn)
            daTrans.Fill(dtTrans)

        Catch ex As Exception
            MsgBox(ex.Message)
            Dim ErrorTitle As String = "Error in PopulateGridwithSQL"
            
        End Try

        Conn.Close()
        Conn = Nothing
        Return dtTrans

    End Function

 
Addendum: I noticed it happens when I come from another page to this page.
I the other page used a GridView2 as well and changed it to Gridview8 but this did not work either.
I changed the page in error to Gridview8 but get a Object not reference when coming back and forth.
If I added this it says Commonname is not in the table?

GridView2.DataSourceID = ""

There seems to be something else wrong and it's tripping on this error when in fact it is something else.

 
Also it is only in the dev environment, whats on the server now runs fine.
I went back and forth many times while it was running on the server and it does not error, just Errors on my Win 7 dev box?
So I am concerned if I upload it, it will break the site :(

 
Ok I fixed it

I added this VB code
Code:
 [highlight #FCE94F]If GridView2.DataSourceID <> "" Then
            GridView2.DataSourceID = ""
 End If[/highlight]
 GridView2.DataSource = PopulateGridwithSQL(SQLString)
 GridView2.DataBind()

then I had to change the SQL to fill the Grid so it did not have aliases
Code:
 SQLString = "SELECT UniqueID, [highlight #FCE94F]CommonName[/highlight] , EmployeeEpriseID , Location, VPName, Nominator, " & _
                            "ReportToManager, Report1, Report2, Report3, AwardType,  convert (nvarchar(12),DateAwarded,101) as DateAwarded, [Event], Awarded, " & _
                            "Left(NominationSummary,100) + '... (Click Edit button <--- to see all)' as NominationSummary, ePrizeID FROM Recognition " & _
                            "Where ePrizeID = '" & Session("ePrizeID") & "' " & _
                            "Order by UniqueID DESC"

then in the MTML markup I changed all of these fields that had an alias to be thus
Code:
<asp:BoundField DataField="[highlight #FCE94F]CommonName[/highlight]" HeaderText="Employeename" 
                    SortExpression="Employeename" />
I also changed the name of the GridView to GridView8 on the other page

 
It may work but it is a hack. Find out where and why the Gridview's datasourceID property is being set.
you have this code
Code:
If GridView2.DataSourceID <> "" Then
            GridView2.DataSourceID = ""
 End If

Debug that code and find out what the datasourceID is when it is not = "". Then you can track down where it is being set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top