473,327 Members | 2,103 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

adding a new row to the repeater control

Dear ASP.NET Programmers,

Here's my problem: I have a page (as usual :), in which I'm going to display invoices in a repeater control. I am binding data to the repeater control (ID: repHospCosts) without any problems. I have also a button on the page, I am going to add a new datarow programmatically and display it when pressed. Unfortunately, I cannot refer to the dataset in the event handler of the button (or at least I think so). I get the following error: Object reference not set to an instance of an object. drow = dtable.NewRow

Below is the code:

Dim dtable As DataTable
Dim drow As DataRow

If Not Page.IsPostBack Then

LoadHospCosts()

End If

Sub LoadHospCosts()

strSql = "spGetHospAmounts"
myCommand.CommandText = strSql
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Clear()
myCommand.Parameters.Add("@ourFileNo", Session("selectedFileNumber"))
myDataAdapter.Fill(myDataSet, "HospCosts")
repHospCosts.DataSource = myDataSet
repHospCosts.DataMember = "HospCosts"
repHospCosts.DataBind()

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

dtable = myDataSet.Tables("HospCosts")
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAmount") = 100
dtable.Rows.Add(drow)
dtable.AcceptChanges()

Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("InvoiceAmount")
Next
lblSubTotal.Text = Format(subTotal, "n")

End Sub

I need any help I can get, thanks in advance...

Buran

Nov 19 '05 #1
2 3628
Hi Buran,

The problem is simple you bind your DataTable only on the first page load,
when you click the button, this is now a postback and you re-bind the data
on postback.

A solution would be to retrieve again the information from the database on a
postback or some mechanism with session or cache to keep it from postback to
postback.

Hope that help.
--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"buran" <b@b.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Dear ASP.NET Programmers,
Here's my problem: I have a page (as usual :), in which I'm going to display
invoices in a repeater control. I am binding data to the repeater control
(ID: repHospCosts) without any problems. I have also a button on the page, I
am going to add a new datarow programmatically and display it when pressed.
Unfortunately, I cannot refer to the dataset in the event handler of the
button (or at least I think so). I get the following error: Object reference
not set to an instance of an object. drow = dtable.NewRow
Below is the code:
Dim dtable As DataTable
Dim drow As DataRow
If Not Page.IsPostBack Then
LoadHospCosts()
End If
Sub LoadHospCosts()
strSql = "spGetHospAmounts"
myCommand.CommandText = strSql
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Clear()
myCommand.Parameters.Add("@ourFileNo",
Session("selectedFileNumber"))
myDataAdapter.Fill(myDataSet, "HospCosts")
repHospCosts.DataSource = myDataSet
repHospCosts.DataMember = "HospCosts"
repHospCosts.DataBind()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
dtable = myDataSet.Tables("HospCosts")
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAmount") = 100
dtable.Rows.Add(drow)
dtable.AcceptChanges()
Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("InvoiceAmount")
Next
lblSubTotal.Text = Format(subTotal, "n")
End Sub
I need any help I can get, thanks in advance...
Buran
Nov 19 '05 #2
Thank you :)

"Jc Morin" <mi****************@jcmorin.net> wrote in message
news:O3**************@TK2MSFTNGP14.phx.gbl...
Hi Buran,

The problem is simple you bind your DataTable only on the first page load,
when you click the button, this is now a postback and you re-bind the data
on postback.

A solution would be to retrieve again the information from the database on a postback or some mechanism with session or cache to keep it from postback to postback.

Hope that help.
--------------------------
Jean-Claude Morin, MCP
Software Developer
2k1Soft/kCentric, Canada
"buran" <b@b.com> wrote in message
news:ee**************@TK2MSFTNGP09.phx.gbl...
Dear ASP.NET Programmers,
Here's my problem: I have a page (as usual :), in which I'm going to display invoices in a repeater control. I am binding data to the repeater control
(ID: repHospCosts) without any problems. I have also a button on the page, I am going to add a new datarow programmatically and display it when pressed. Unfortunately, I cannot refer to the dataset in the event handler of the
button (or at least I think so). I get the following error: Object reference not set to an instance of an object. drow = dtable.NewRow
Below is the code:
Dim dtable As DataTable
Dim drow As DataRow
If Not Page.IsPostBack Then
LoadHospCosts()
End If
Sub LoadHospCosts()
strSql = "spGetHospAmounts"
myCommand.CommandText = strSql
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.Clear()
myCommand.Parameters.Add("@ourFileNo",
Session("selectedFileNumber"))
myDataAdapter.Fill(myDataSet, "HospCosts")
repHospCosts.DataSource = myDataSet
repHospCosts.DataMember = "HospCosts"
repHospCosts.DataBind()

End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
dtable = myDataSet.Tables("HospCosts")
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAmount") = 100
dtable.Rows.Add(drow)
dtable.AcceptChanges()
Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("InvoiceAmount")
Next
lblSubTotal.Text = Format(subTotal, "n")
End Sub
I need any help I can get, thanks in advance...
Buran

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jax | last post by:
I am looking to populate web page with controls as a result of a database query. eg (pseudocode) <% foreach(Garment g in GetStuffFromDB()) { //add controls Response.Write("<asp:Button id =...
4
by: Neven Klofutar | last post by:
Hi, How can I add an even handler to a control that is not situated on the main page (it's situated in the repeater). How do I rewrite this to make it work ? Thanx, Neven ...
8
by: Invalidlastname | last post by:
Hi, We are developing an asp.net application, and we dynamically created certain literal controls to represent some read-only text for certain editable controls. However, recently we found an issue...
0
by: Charlie | last post by:
Hi: I'm using the Repeater control to display one-to-many relationship between Customer, Orders and Order Items. To do this, I bind the control to Customer table to show customer data, then...
1
by: olduncleamos | last post by:
Hello all, I am experimenting with the repeater control and ran into something that I wasn't expecting. I would appreciate if the experts can confirm or correct my understanding. Here is a...
3
by: Fao, Sean | last post by:
I have a DataGrid that I'm adding CheckBox controls to at runtime (in the code behind) and I'm not sure if I'm doing it correctly. First of all, I noticed that the MyDataGrid.Columns.Add() method...
8
by: fernandezr | last post by:
I would like to use a user control as a template inside a repeater. Some of the fields in the control should be hidden depending on whether or not there is data. I'm still a ASP .Net newbie so the...
6
by: Totto | last post by:
Hi, Anyone know the best solution to dynamically add buttons to a asp 2.0 page using data from Sql server? Are there any contols suitable for this or is it best to iterate the dataset and...
2
by: Nathan Sokalski | last post by:
I am write a CompositeControl, and one of the controls being included is a Repeater. This is my first time including a templated control in a control other than a UserControl. I am not sure how to...
7
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
I'm adding subheadings to a gridview. Each sub head has a few link buttons. I'm adding the controls in the rowdatabound event code follows: sorry about the length here. I have to be missing...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.