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
VBA code with DataSource
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>
Surname
<asp:TextBox ID="txtFindSurName" runat="server" Width="100px"></asp:TextBox>
<asp:Button ID="btnFindEmployee" runat="server" Text="Find Employee"
Width="129px" />
<asp:Button ID="btnReset" runat="server" Text="Reset" Visible="False" />
<asp:TextBox ID="txtEnterpriseID" runat="server" Width="107px"
Visible="False"></asp:TextBox>
<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=" "Yellow Highlighted rows are NON-employees. Please do not choose.""
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>
Surname
<asp:TextBox ID="txtFindNominatorSurName" runat="server" Width="100px"></asp:TextBox>
<asp:Button ID="btnFindNominator" runat="server" Text="Find Nominator"
Width="129px" />
<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=" "Yellow Highlighted rows are NON-employees. Please do not choose.""
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>
<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>
<asp:Button ID="btnToday" runat="server" Text="Today" />
<asp:TextBox ID="txtRecognitionDate" runat="server" Width="145px"></asp:TextBox>
<asp:Button ID="btnShowCalendar" runat="server" Text="Calendar" Width="88px" />
<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>
<asp:DropDownList ID="ddlAwardTypes" runat="server" Height="22px" Width="190px">
</asp:DropDownList>
<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 "></asp:Label>
<asp:TextBox ID="txtEvent" runat="server" Width="194px"></asp:TextBox>
<br />
<asp:Label ID="Label2" runat="server" Font-Bold="True" ForeColor="Black"
Text="Awarded"></asp:Label>
<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" />
<asp:Button ID="btnReset2" runat="server"
Font-Size="Large" Height="30px"
Text="Reset" Width="120px" style="margin-top: 6px" />
<!------------------------------ 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