I am having a little problem with my editable data grid and it's binding and I was hoping someone might clue me in to what it is doing.<BR><BR>When I run my page and trace the debugger, I first go to my Page_Load which calls BindGrid(). The page loads and it fine.<BR>When I hit the edit link, I go to PageLoad again, which does not run BindGrid() due to the fact that it is in a "If Not IsPostBack Then" statement. Then my page stops running and it doesn't even make it to the DataGrid_Edit() sub. Therefore I get a blank page. If I take out the "If Not IsPostBack Then" from the Page_Load, then I get a referncing error, probably because BindGrid is running twice.<BR><BR>I cannot figure out how to fix this!<BR><BR>Here is my code, for you all to take a look at.<BR><BR>Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load<BR> 'Put user code to initialize the page here<BR> MyConnection = New SqlConnection("xxxx")<BR> 'StaffNames()<BR> If Not (IsPostBack) Then<BR> BindGrid()<BR> End If<BR> End Sub<BR><BR>Sub DataGrid_Edit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)<BR><BR> DataGrid.EditItemIndex = CInt(E.Item.ItemIndex)<BR> BindGrid()<BR> End Sub<BR><BR><BR>Private Sub BindGrid()<BR> Dim sdaBindGrid As SqlDataAdapter<BR> Dim DSBindGrid As DataSet<BR> Dim strStaffRoles As String<BR><BR> strStaffRoles = "select iProjectStaffID, vFirstName+' '+vLastName as FullName, vRoleName from ProjectStaff PS inner join Staff S on PS.iStaffID = S.iStaffID inner join Roles R on PS.iRoleID = R.iRoleID and PS.iProjectID='" & intTempProjectID & "'"<BR><BR> sdaBindGrid = New SqlDataAdapter(strStaffRoles, MyConnection)<BR> DSBindGrid = New DataSet()<BR> sdaBindGrid.Fill(DSBindGrid, "StaffRoles")<BR><BR> DataGrid.DataSource = DSBindGrid.Tables("StaffRoles").DefaultView<BR> DataGrid.DataBind()<BR> End Sub<BR><BR><BR>Here is my data grid declaration(i took some irrelevant stuff out):<BR><ASP
ataGrid id="DataGrid" runat="server"<BR>EnableViewState="false" <BR>OnEditCommand="DataGrid_Edit" OnCancelCommand="DataGrid_Cancel" OnUpdateCommand="DataGrid_Update" DataKeyField="iProjectStaffID" AutoGenerateColumns="false" OnItemDataBound="DataGrid_ItemDataBound"><BR><BR><BR>If anyone has seen this before or has a clue, please let me know!<BR>Thanks sooooo much in advanceif you can help
The DataGrid does not show up because you set:<BR>EnableViewState="false"<BR><BR>Change it to:<BR>EnableViewState="true"<BR><BR>Aaron<BR>That worked Thanks!<BR>Now I am getting a stupid "System.NullReferenceException: Object reference not set to an instance of an object"<BR>On the last databind(). Is that because I already binded the data once already? <BR><BR>Any ideas on this? Thanks a bunch!Looking at your code again I noticed that you call your DataGrid<BR>"DataGrid".<BR><BR>This might be the problem. <BR>Try changing the name to "DataGrid1" or "MyDataGrid".<BR>I think "DataGrid" is a keyword. Even if it is not the problem it still is a good idea to name controls by their control name.<BR><BR>Aaron<BR><BR><BR>You need to be careful using EnableViewState=True though - just load up a big DataGrid and look at the source!! The web page is passing the entire DataGrid to itself whenever it reloads which is fine if you are on a fast intranet or have a small amount of data in your DataGrid... otherwise your users could be in for long downloads and very slow pages!<BR><BR>You can look at using Session variables to hold the Dataset/Dataview. I use DataView caching myself which works very well.<BR><BR>Mike.I have a big datagrid and would like to disable the viewstate, but i get the same blank page.<BR><BR>Do you have any exemple of tutorial on how to use the session var or dataview cacheing to make it work ?

