Reputation:
Got a bit of a weird one here. I'm adding a GridView to my webpage using the following code:
<asp:GridView ID="grdMain" runat="server" AutoGenerateColumns="False" DataKeyNames="Field1" DataSourceID="GridDataSource" EnableViewState="False" CssClass="TriageList" OnRowDataBound="grdListRowDataBound" AlternatingRowStyle-CssClass="GridAlternateRow" HeaderStyle-CssClass="GridHeader" RowStyle-CssClass="GridRow" PagerStyle-CssClass="GridPager">
<Columns>
<asp:BoundField DataField="Field1" ReadOnly="true" HeaderText="Field1" />
<asp:BoundField DataField="Field2" ReadOnly="true" HeaderText="Field2" />
<asp:BoundField DataField="Field3" ReadOnly="true" HeaderText="Field3" />
</Columns>
</asp:GridView>
<asp:SqlDataSource
ID="GridDataSource" runat="server"
SelectCommand="SELECT [Name] FROM [Table] ORDER BY [Name]">
</asp:SqlDataSource>
I have 4 of these grids on my webpage and they are all working fine. However, as soon as I add another GridView, it displays this following message:
The ConnectionString property has not been initialized.
The additional GridView I'm adding is using the same code as the above snippet, it however is using a different name for the following elements:
I'm not sure why just adding an additional grid is stopping this from working, if I remove the grid it works fine.
I've also tried removing the OnRowDataBound reference so it's not running any code behind it but that doesn't help.
Any help would be appreciated.
Upvotes: 0
Views: 36
Reputation:
Simple overlooked problem, I forgot to set a ConnectionString for the SQLDataSource, I didn't do this in the code when creating them as they were assigned dynamically, the following piece of code fixed this for me.
GridDataSource.ConnectionString = varConnectionString;
Upvotes: 1