Hi all,
Hopefully someone can help. Just started Visual Basic - using Visual Studio 2005 pro
and connecting to a sql database on a seperate server
Entered the code from the Try it Out on Page 575 with some amendments as follows to connect to the sql database.
<%@PageLanguage="VB"AutoEventWireup="false"CodeFile="Default.aspx.vb"Inherits="_Default" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Grid View</title>
</head>
<body>
<formid="form1"runat="server">
<div>
<asp:sqlDataSourceID="tblAnimalTypes"runat="server"providername="System.Data.SqlClient"
connectionstring="Server=*********; User ID=AME;
password=********* ;database=AME;"
SelectCommand="SELECT txtAnimal, txtColour FROM tblAnimalTypes"
UpdateCommand="UPDATE tblAnimaltypes SET txtColour = @txtColour where txtAnimal = @original_txtAnimal">
<UpdateParameters>
<asp:ParameterType="String"Name="txtAnimal"/><asp:Parameter/>
<asp:ParameterType="String"Name="txtColour"/><asp:Parameter/>
</UpdateParameters>
</asp:sqlDataSource>
<asp:DataGridID="gdvAnimals"Runat="Server"DataSourceID="tblAnimalTypes"
allowpaging="true"AllowSorting="true"AutoGenerateColumns="true"DataKeyField="txtAnimal">
<PagerStyleBackColor="Gray"ForeColor="White"HorizontalAlign="Center"/>
<Headerstylebackcolor="black"ForeColor="white"/>
<AlternatingItemStyleBackColor="LightGray"/>
<Columns>
<asp:CommandFieldbuttontype="Button"showeditbutton="true"/>
</Columns></asp:DataGrid></div>
</form>
</body>
</html>
Without the <asp:CommandField line the data grid is shown with data from the database but with any editing facilities
With the <asp:CommandField line the following error is given
Error 1 System.Web.UI.WebControls.DataGridColumnCollection must have items of type 'System.Web.UI.WebControls.DataGridColumn'. 'asp:CommandField' is of type 'System.Web.UI.WebControls.CommandField'. C:\WebSite\DataGridView\Default.aspx 31
The default.aspx.
vb has the following
PartialClass _Default
Inherits System.Web.UI.Page
EndClass
Any help would be appreciated