Please help my grideview does not work despite trying several examples and changing some setting on the gridview as advised on this forum
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="Stockbooks" runat="server" ClientIDMode="Static" OnRowDataBound="OnRowDataBound" AutoGenerateColumns="False" DataKeyNames="Autofield" Width="16px" ShowFooter="True"
Height="16px" PageSize="10">
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkAll" runat="server" AutoPostBack="true" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox" runat="server" AutoPostBack="true" OnCheckedChanged="OnCheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Account" ItemStyle-Width="50">
<FooterTemplate>
<asp:TextBox ID="Tfadmno" runat="server" Style="margin-bottom: 0px"
Height="16px" Width="80px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Ladmno" runat="server" Text='<%# Eval("admno") %>'></asp:Label>
<asp:TextBox ID="Txtadmno" runat="server" Text='<%# Eval("admno") %>'
Visible="false" Height="19px" Width="78px"
AutoPostBack="True"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Student Name" ItemStyle-Width="170">
<FooterTemplate>
<asp:TextBox ID="FstudentName" runat="server" Style="margin-bottom: 0px"
Height="19px" Width="164px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="LblStudentName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
<asp:TextBox ID="TxtStudentname" runat="server" Text='<%# Eval("Name") %>'
Visible="false" Height="16px" Width="165px"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="250px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Class" ItemStyle-Width="150">
<FooterTemplate>
<asp:DropDownList ID="FDropClass" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1pp" DataTextField="Class" DataValueField="Class" Height="18px" Width="72px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1pp" runat="server" ConnectionString="<%$ ConnectionStrings:STOREConnectionString1 %>" SelectCommand="SELECT [Class] FROM [Classes]"></asp:SqlDataSource>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Lclass" runat="server" Text='<%# Eval("Classr") %>'></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Stream" ItemStyle-Width="150">
<FooterTemplate>
<asp:Label ID="Lblstream" runat="server" Text="Label"></asp:Label>
<asp:DropDownList ID="ddlStreamF" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1BT" DataTextField="stream" DataValueField="stream" Height="22px" OnSelectedIndexChanged="DropDown_Changed" Width="105px">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1BT" runat="server" ConnectionString="<%$ ConnectionStrings:STOREConnectionString1 %>" SelectCommand="SELECT [stream] FROM [streamdata]"></asp:SqlDataSource>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Lblstream" runat="server" Text='<%# Eval("Stream") %>'></asp:Label>
<asp:DropDownList ID="ddlStream" runat="server"
OnSelectedIndexChanged="DropDown_Changed" AutoPostBack="True" Height="20px" Width="105px">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="STDTYPE" ItemStyle-Width="50">
<FooterTemplate>
<asp:Label ID="LblSTDTYPEF" runat="server" Text='<%# Eval("STDTYPE") %>'></asp:Label>
<asp:DropDownList ID="ddlSTDTYPE" runat="server" AutoPostBack="True" DataTextField="STDTYPE" DataValueField="STDTYPE" Height="16px" OnSelectedIndexChanged="DropDown_Changed" Width="105px">
<asp:ListItem>Old</asp:ListItem>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Old Repeater</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="LblSTDTYPE" runat="server" Text='<%# Eval("STDTYPE") %>'></asp:Label>
<asp:DropDownList ID="ddlSTDTYPE0" runat="server" AutoPostBack="True" DataTextField="STDTYPE" DataValueField="STDTYPE" Height="16px" OnSelectedIndexChanged="DropDown_Changed" Width="105px">
<asp:ListItem>Old</asp:ListItem>
<asp:ListItem>New</asp:ListItem>
<asp:ListItem>Old Repeater</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="50px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sex" ItemStyle-Width="150">
<FooterTemplate>
<asp:Label ID="Label38" runat="server" Text="Lblsexf"></asp:Label>
<asp:DropDownList ID="ddlSexF" runat="server" AutoPostBack="True" Height="18px" OnSelectedIndexChanged="DropDown_Changed" Width="105px">
<asp:ListItem>Female</asp:ListItem>
<asp:ListItem>NONE</asp:ListItem>
<asp:ListItem>Male</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Lblsex" runat="server" Text='<%# Eval("Sex") %>'></asp:Label>
<asp:DropDownList ID="Dropdownlist2" runat="server" AutoPostBack="True" Height="20px" OnSelectedIndexChanged="DropDown_Changed" Width="105px">
</asp:DropDownList>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Colour" ItemStyle-Width="150">
<FooterTemplate>
<asp:TextBox ID="Yrcolour" runat="server" Height="20px" Width="117px"></asp:TextBox>
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="Lblcolour" runat="server" Text='<%# Eval("House") %>'></asp:Label>
<asp:TextBox ID="Txtcolour" runat="server" Text='<%# Eval("House") %>'
Visible="false" Height="20px" Width="119px"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="150px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ACNOS">
<FooterTemplate>
<asp:Button ID="Button5" runat="server" OnClick="AddNewBook" Text="Add New Student" />
</FooterTemplate>
<ItemTemplate>
<asp:Label ID="LACNOS" runat="server" Text='<%# Eval("ACNOS") %>'></asp:Label>
<asp:TextBox ID="TxtACNOS" runat="server" Height="21px"
Text='<%# Eval("ACNOS") %>' Visible="False" Width="74px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<SelectedRowStyle BackColor="#CC00FF" />
</asp:GridView>
</div>
</form>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.min.js"></script>
<link href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$("[id*=Stockbooks]").DataTable(
{
bLengthChange: true,
lengthMenu: [[5, 10, -1], [5, 10, "All"]],
bFilter: true,
bSort: true,
bPaginate: true
});
});
</script>
</body>
</html>
VB.Net
Public Class Searchstudentdata
Inherits System.Web.UI.Page
Dim conString As String = ConfigurationManager.ConnectionStrings("STOREConnectionString1").ConnectionString
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BindGrid()
Enablall()
End If
End Sub
Private Function ExecuteQuery(ByVal cmd As SqlCommand, ByVal action As String) As DataTable
'Dim conString As String = conString
Using con As New SqlConnection(conString)
cmd.Connection = con
Select Case action
Case "SELECT"
Using sda As New SqlDataAdapter()
sda.SelectCommand = cmd
Using dt As New DataTable()
sda.Fill(dt)
Return dt
End Using
End Using
Case "UPDATE"
con.Open()
cmd.ExecuteReader()
con.Close()
Exit Select
End Select
Return Nothing
End Using
End Function
Private Sub BindGrid()
Dim cmd As New SqlCommand("SELECT Name,class as Classr,stream, House, ACNOS,admno,sex,STDTYPE,Autofield FROM STUDENT")
Stockbooks.DataSource = Me.ExecuteQuery(cmd, "SELECT")
Stockbooks.DataBind()
End Sub
End Class