Hello i have a dynamic datatable in my page. I wanna to write data to
textboxes and after click on button "ADD data" i want to refresh datagrid on
page... Here is my code :
' Insert page code here
'
Dim wykszt as System.Data.DataTable
Dim zatru as System.Data.DataTable
Dim row as system.Data.DataRow
Private Sub Page_Load(s As Object, e As EventArgs)
if Not IsPostBack Then
make_d_tables()
End if
End Sub
Function make_d_tables()
wykszt = New System.Data.DataTable("wykszt")
wykszt.Columns.Add("od_data", GetType(date))
wykszt.Columns.Add("do_data", GetType(date))
wykszt.Columns.Add("nazwa_szkoly", GetType(String))
wykszt.Columns.Add("nazwa_tytulu", GetType(String))
zatru = New System.Data.DataTable("zatr")
zatru.Columns.Add("od_data", GetType(date))
zatru.Columns.Add("do_data", GetType(date))
zatru.Columns.Add("nazwa_prac", GetType(String))
zatru.Columns.Add("nazwa_stan", GetType(String))
End Function
Sub Button2_Click(sender As Object, e As EventArgs)
row = wykszt.NewRow
row("od_data")=TextBox27.Text + "-01"
row("do_data")=TextBox28.Text + "-01"
row("nazwa_szkoly")=TextBox29.Text
row("nazwa_tytulu")=TextBox30.Text
wykszt.Rows.Add(rowe)
datagrid1.datasource=wykszt
datagrid1.databind
End Sub
.....
but something not works....
i have an exception with this code but when i use page_init like :
Private Sub Page_init(s As Object, e As EventArgs)
make_d_tables()
End Sub
it`s start to works but in datagrid i have all time one position. I think
that page_init is called all the time i click button "add data" and
initialise tables all the time
I wanna add rows to datatable after clickin "Add data" and to dynamicaly
refresh datagrid ??? how to make it ????
And one more question
After click on button page is reloaded and set on the top of the page. How
can i do thaT after click page is in the same place like before ???
Thanks
Pat 2 2103
Sorry this line isnt wykszt.Rows.Add(rowe) but wykszt.Rows.Add(row)
Użytkownik "ven" <ve*****@poczta.onet.pl> napisał w wiadomo¶ci
news:ci*********@news.onet.pl... Hello i have a dynamic datatable in my page. I wanna to write data to textboxes and after click on button "ADD data" i want to refresh datagrid
on page... Here is my code :
' Insert page code here '
Dim wykszt as System.Data.DataTable Dim zatru as System.Data.DataTable Dim row as system.Data.DataRow
Private Sub Page_Load(s As Object, e As EventArgs) if Not IsPostBack Then make_d_tables() End if End Sub
Function make_d_tables()
wykszt = New System.Data.DataTable("wykszt") wykszt.Columns.Add("od_data", GetType(date)) wykszt.Columns.Add("do_data", GetType(date)) wykszt.Columns.Add("nazwa_szkoly", GetType(String)) wykszt.Columns.Add("nazwa_tytulu", GetType(String))
zatru = New System.Data.DataTable("zatr") zatru.Columns.Add("od_data", GetType(date)) zatru.Columns.Add("do_data", GetType(date)) zatru.Columns.Add("nazwa_prac", GetType(String)) zatru.Columns.Add("nazwa_stan", GetType(String))
End Function
Sub Button2_Click(sender As Object, e As EventArgs)
row = wykszt.NewRow row("od_data")=TextBox27.Text + "-01" row("do_data")=TextBox28.Text + "-01" row("nazwa_szkoly")=TextBox29.Text row("nazwa_tytulu")=TextBox30.Text wykszt.Rows.Add(rowe)
datagrid1.datasource=wykszt datagrid1.databind
End Sub
.... but something not works.... i have an exception with this code but when i use page_init like :
Private Sub Page_init(s As Object, e As EventArgs) make_d_tables() End Sub
it`s start to works but in datagrid i have all time one position. I think that page_init is called all the time i click button "add data" and initialise tables all the time I wanna add rows to datatable after clickin "Add data" and to dynamicaly refresh datagrid ??? how to make it ???? And one more question After click on button page is reloaded and set on the top of the page. How can i do thaT after click page is in the same place like before ???
Thanks
Pat
> but something not works.... i have an exception with this code but when i use page_init like :
You will have an exception with this code. When the page posts back, you
are not creating the DataTables.
wykszt will be null. I am guessing you are receiving and NullException or a
object not set exception.
If you put your Page_Init, into the Page_Load but remove the IsPostBack
check, you will no longer receive the exception.
I would recommend (others will probably lambast me over this) not placing
anything into the Page_Init method until you are more comfortable with the
framework. I have spent many hours debugging control loading and certain
controls not being completely loaded.
With your code as so, you will be adding one line to a DataGrid, and the
next time they hit the "Add" button, it will essentially replace the
previous line with the new line. To keep adding rows to the DataGrid, you
should use either Session or ViewState. Viewstate if you don't have many
rows, Session if you don't have many users.
As far as saving the scroll position on postback. You can turn on Smart
Navigation or write your own. I have read countless problems with Smart
Navigation so I would suggest writing your own. You will need to use client
side script and add onto the "onsubmit" handler for the form.
This is by no means good code, but you will get the gist. Infact, this is
no where near production grade code. Hell, I don't even know if this is
correct syntax. I am c# guy.
sub Page_Load(..)
'check to see if it is in session memory.
if Session("wykszt") IS Nothing then
make_d_table()
end if
if Not IsPostBack Then
datagrid1.datasource= Session( "wykszt" )
datagrid1.databind
end if
end sub
Sub Button2_Click(sender As Object, e As EventArgs)
Dim wykszt as System.Data.DataTable
'pull it out of session.
wykszt = Session( "wykszt" )
row = wykszt.NewRow
row("od_data")=TextBox27.Text + "-01"
row("do_data")=TextBox28.Text + "-01"
row("nazwa_szkoly")=TextBox29.Text
row("nazwa_tytulu")=TextBox30.Text
wykszt.Rows.Add(rowe)
datagrid1.datasource=wykszt
datagrid1.databind
End Sub
Function make_d_tables()
Dim wykszt as System.Data.DataTable
Dim zatru as System.Data.DataTable
wykszt = New System.Data.DataTable("wykszt")
wykszt.Columns.Add("od_data", GetType(date))
wykszt.Columns.Add("do_data", GetType(date))
wykszt.Columns.Add("nazwa_szkoly", GetType(String))
wykszt.Columns.Add("nazwa_tytulu", GetType(String))
zatru = New System.Data.DataTable("zatr")
zatru.Columns.Add("od_data", GetType(date))
zatru.Columns.Add("do_data", GetType(date))
zatru.Columns.Add("nazwa_prac", GetType(String))
zatru.Columns.Add("nazwa_stan", GetType(String))
'this will save it into session memory.
Session("wykszt") = wykszt
Session( "zatru" ) = zatru
End Function
HTH,
bill
"ven" <ve*****@poczta.onet.pl> wrote in message
news:ci*********@news.onet.pl... Hello i have a dynamic datatable in my page. I wanna to write data to textboxes and after click on button "ADD data" i want to refresh datagrid
on page... Here is my code :
' Insert page code here '
Dim wykszt as System.Data.DataTable Dim zatru as System.Data.DataTable Dim row as system.Data.DataRow
Private Sub Page_Load(s As Object, e As EventArgs) if Not IsPostBack Then make_d_tables() End if End Sub
Function make_d_tables()
wykszt = New System.Data.DataTable("wykszt") wykszt.Columns.Add("od_data", GetType(date)) wykszt.Columns.Add("do_data", GetType(date)) wykszt.Columns.Add("nazwa_szkoly", GetType(String)) wykszt.Columns.Add("nazwa_tytulu", GetType(String))
zatru = New System.Data.DataTable("zatr") zatru.Columns.Add("od_data", GetType(date)) zatru.Columns.Add("do_data", GetType(date)) zatru.Columns.Add("nazwa_prac", GetType(String)) zatru.Columns.Add("nazwa_stan", GetType(String))
End Function
Sub Button2_Click(sender As Object, e As EventArgs)
row = wykszt.NewRow row("od_data")=TextBox27.Text + "-01" row("do_data")=TextBox28.Text + "-01" row("nazwa_szkoly")=TextBox29.Text row("nazwa_tytulu")=TextBox30.Text wykszt.Rows.Add(rowe)
datagrid1.datasource=wykszt datagrid1.databind
End Sub
.... but something not works.... i have an exception with this code but when i use page_init like :
Private Sub Page_init(s As Object, e As EventArgs) make_d_tables() End Sub
it`s start to works but in datagrid i have all time one position. I think that page_init is called all the time i click button "add data" and initialise tables all the time I wanna add rows to datatable after clickin "Add data" and to dynamicaly refresh datagrid ??? how to make it ???? And one more question After click on button page is reloaded and set on the top of the page. How can i do thaT after click page is in the same place like before ???
Thanks
Pat
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Emerson |
last post by:
The following assumes a System.Windows.Forms.DataGrid with a System.Data.DataTable set as the DataSource. I'm programming in C#
Here's my scenario
I click in a cell on a DataGrid. I enter some...
|
by: Newbie |
last post by:
I am using a Datagrid to show the contents of a DataTable. But it seems like
the Datagrid is not getting the contents of the Datatable when the button (
btnAddAnotherLaborCategory) is clicked.
...
|
by: Saso Zagoranski |
last post by:
hi,
this is not actually a C# problem but since this is the only newsgroup I
follow I decided
to post my question here (please tell me where to post this next time if you
think this post...
|
by: Inigo Jimenez |
last post by:
I have an ASP .net web application installed in a Windows 2003 server.
This web application has a webform that has a Datagrid.
This Datagrid is filled with the data of a SQL table.
I have a...
|
by: The Alchemist |
last post by:
I am having a problem with a dynamically-generated Datagrid. It is
important to point out that this problem does not exist with a
design-time created Datagrid, but only with a dynamically generated...
|
by: tangus via DotNetMonster.com |
last post by:
Hello all, I'm really struggling with getting some Active Directory code to
work in ASP.NET. Can you please provide assistance? I am executing the
following code:
Dim enTry As DirectoryEntry =...
|
by: sapkal.manish |
last post by:
Question : How can I find actual row position of DataTable in
DataGridView when DataTable is sorted
/ My source code like this
Private WithEvent dgvInwDet as new DataGridView
Private...
|
by: Aryan |
last post by:
Hi,
I am having problem with DataTable.Select() method. I am using
ASP.NET 2.0.
I have DataSet which reads data from XML file using DataSet.ReadXML().
Now this
dataset has various datatable,...
|
by: Vlado Jasovic |
last post by:
Hello,
I'm using typed dataset for databinding to windows controls and I'm having
some problems.
I'm trying to move all business logic to datatable column_changing events
and the problem that...
|
by: tomash |
last post by:
Hi!
I ve got two tables in Access 2007.
I want to update a field of DataTable from another table, DataSumTable when two of their fields equals.
( the fields : Name and Period)
I tried this...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |