|
-
May 27th, 2005, 06:33 PM
#1
Thread Starter
Hyperactive Member
datagrids disapear on postback
I define my datagrids by vb-code (no AutoGenerateColumns) on the first load of my page (If Not Page.IsPostBack Then...). On the first load everything is fine.
But once the user interacts (for example clicks on a calendar-object) the datagrids disabear! Only the datagrids disapear, not other elements - event text that was written in a textbox is stored and reloaded when the user does a postback... but not the datagrids.
Is this normal?
Thank you very much for your help !
P.S. By the way, I am still looking for someone who could be so kind and help me with this other datagrid-problem :
http://www.vbforums.com/showthread.p...17#post2026217
-
May 27th, 2005, 09:38 PM
#2
Re: datagrids disapear on postback
What happens when you remove the Postback check?
-
May 28th, 2005, 05:00 AM
#3
Thread Starter
Hyperactive Member
Re: datagrids disapear on postback
Hi mendhak,
what postback check ?
I can not find any postback check in the datagrid properties!
But here is an additional information. As I told in my first post, I did create columns by vb-code (see code beneath).
But, if I create a datagrid and I define the columns in the aspx-page like this it works!
HTML Code:
<asp:datagrid id="myDataGrid_lastConsumedProducts" style="Z-INDEX: 123; LEFT: 752px; POSITION: absolute; TOP: 80px" runat="server" Width="168px" AutoGenerateColumns="False" OnItemCommand="viewRow" DataKeyField="product_id">
<Columns>
<asp:ButtonColumn DataTextField="fullProductName" CommandName="SelsfdectItem"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
Now this rejoins a bit my other problem:
http://www.vbforums.com/showthread.p...17#post2026217
Because like in this other problem about datagrids (specifically concerning buttonColumns) the vb-code seems to make problems. I call this code (see beneath) only once at the first upload of the page (not at postbacks), as the data do not change (and if they change I recall the same function again that I use at the first upload).
So probably there is a problem in my vb-code (see beneath). But I really need to be able to define the content of my datagrids by vb-code, so if you could help me to understand the problem I would be more than glad!
Here is the vb-code for defining and filling a datagrid and there are two problems with it : first on postbacks the datagrid disabears and secondly I do not know how to make that the buttonColumn that I create here starts a mySub when it is clicked...
VB Code:
Function fill_myDataGrid_todayConsumptions(ByVal Datehour_start As Date, ByVal Datehour_end As Date)
Dim field_list(,) As String = _
{{"id", "id"}, _
{"consumptionDate", translate("consumption date", , myUser.language_id)}, _
{"fullProductName", translate("product name", , myUser.language_id)}, _
{"weight", translate("weight", , myUser.language_id)}, _
{"unit", translate("unit", , myUser.language_id)}, _
{"productCondition", translate("product condition", , myUser.language_id)}}
Dim myDataset As DataSet = myConsumptions.get_Dataset_of_Consumptions(field_list)
myDataGrid_todayConsumptions.AutoGenerateColumns = False
myDataGrid_todayConsumptions.DataSource = myDataset
myDataGrid_todayConsumptions.DataKeyField = "id"
Dim myColumn As BoundColumn
For i As Integer = 0 To field_list.Length / field_list.Rank - 1
myColumn = New BoundColumn
myColumn.DataField = field_list(i, 0)
myColumn.HeaderText = field_list(i, 1)
If i = 0 Then myColumn.Visible = False
myDataGrid_todayConsumptions.Columns.Add(myColumn)
Next
myDataGrid_todayConsumptions.HeaderStyle.CssClass = "Lable"
Dim myButtonColumn As ButtonColumn = New ButtonColumn
myButtonColumn.Text = translate("Edit", , myUser.language_id)
myButtonColumn.ItemStyle.CssClass = "datagridEditButton"
myButtonColumn.CommandName = "Delete"
myDataGrid_todayConsumptions.Columns.Add(myButtonColumn)
myDataGrid_todayConsumptions.DataBind()
End Function
-
May 28th, 2005, 12:15 PM
#4
Re: datagrids disapear on postback
Havent read the rest of the reply so not sure if you have solved your problem. But usually if you have the EnableViewState property to false then your DataGrid will dissappear if you are binding it dynamically. So check the EnableViewState property of your datagrid.
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
-
May 28th, 2005, 12:42 PM
#5
Thread Starter
Hyperactive Member
Re: datagrids disapear on postback
EnableViewState was checked (true). But by changing this the problem does not solve.
Do you have any other idea?
-
May 28th, 2005, 10:11 PM
#6
Re: datagrids disapear on postback
Postback check = "If Not Page.IsPostBack Then.."
-
May 29th, 2005, 07:38 AM
#7
Thread Starter
Hyperactive Member
Re: datagrids disapear on postback
Hi mendhak,
If I get off the Postback check, the content of the datagrid will be defined at each postback (even if the data do not change), and this would cost time...
I played a bit around to understand what happens, and I think that I have the answer - could you please tell me what you think about it?
Normally the "enableViewState" indicates, if the page-object should keep the control's state in memory from one postback to the next, so that data are not lost – right?
But this seems only to work if the columns of the datagrid are defined in the html-code of the aspx-page … and not if the columns are added by code.
What do you think about it? Could this be?
Here my text-code, in this case too the datagrid disappears once the button is clicked!
VB Code:
Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents TextBox1 As System.Web.UI.WebControls.TextBox
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim myDBconnectionManagement As New db_connection_management
myDBconnectionManagement.SetConnection()
Dim myDataset As DataSet = New DataSet
Dim sql As String = "select * from consumption"
myDBconnectionManagement.fill_dataset(myDataset, sql, "table")
Dim field_list(,) As String = _
{{"id", "id"}, _
{"Date", Translate("consumption date")}, _
{"Product_id", Translate("product name")}, _
{"weight", Translate("weight")}, _
{"unit_id", Translate("unit")}, _
{"product_condition_id", Translate("product condition")}}
Dim myColumn As BoundColumn
For i As Integer = 0 To field_list.Length / field_list.Rank - 1
myColumn = New BoundColumn
myColumn.DataField = field_list(i, 0)
myColumn.HeaderText = field_list(i, 1)
If i = 0 Then myColumn.Visible = False
DataGrid1.Columns.Add(myColumn)
Next
Dim myButtonColumn As ButtonColumn = New ButtonColumn
myButtonColumn.Text = Translate("Edit")
myButtonColumn.ItemStyle.CssClass = "datagridEditButton"
myButtonColumn.CommandName = "Delete"
DataGrid1.Columns.Add(myButtonColumn)
DataGrid1.AutoGenerateColumns = False
DataGrid1.DataSource = myDataset
DataGrid1.DataKeyField = "id"
DataGrid1.HeaderStyle.CssClass = "label"
DataGrid1.ItemStyle.CssClass = "datagrid"
DataGrid1.DataBind()
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
TextBox1.Text = "now the datagrid will not show-up anymore!"
End Sub
End Class
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|