473,809 Members | 2,876 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 programmaticall y 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 = "spGetHospAmoun ts"
myCommand.Comma ndText = strSql
myCommand.Comma ndType = CommandType.Sto redProcedure
myCommand.Param eters.Clear()
myCommand.Param eters.Add("@our FileNo", Session("select edFileNumber"))
myDataAdapter.F ill(myDataSet, "HospCosts" )
repHospCosts.Da taSource = myDataSet
repHospCosts.Da taMember = "HospCosts"
repHospCosts.Da taBind()

End Sub

Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As System.EventArg s) Handles Button2.Click

dtable = myDataSet.Table s("HospCosts" )
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAm ount") = 100
dtable.Rows.Add (drow)
dtable.AcceptCh anges()

Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("Invo iceAmount")
Next
lblSubTotal.Tex t = Format(subTotal , "n")

End Sub

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

Buran

Nov 19 '05 #1
2 3658
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******** ******@TK2MSFTN GP09.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 programmaticall y 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 = "spGetHospAmoun ts"
myCommand.Comma ndText = strSql
myCommand.Comma ndType = CommandType.Sto redProcedure
myCommand.Param eters.Clear()
myCommand.Param eters.Add("@our FileNo",
Session("select edFileNumber"))
myDataAdapter.F ill(myDataSet, "HospCosts" )
repHospCosts.Da taSource = myDataSet
repHospCosts.Da taMember = "HospCosts"
repHospCosts.Da taBind()

End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
dtable = myDataSet.Table s("HospCosts" )
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAm ount") = 100
dtable.Rows.Add (drow)
dtable.AcceptCh anges()
Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("Invo iceAmount")
Next
lblSubTotal.Tex t = 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.ne t> wrote in message
news:O3******** ******@TK2MSFTN GP14.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******** ******@TK2MSFTN GP09.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 programmaticall y 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 = "spGetHospAmoun ts"
myCommand.Comma ndText = strSql
myCommand.Comma ndType = CommandType.Sto redProcedure
myCommand.Param eters.Clear()
myCommand.Param eters.Add("@our FileNo",
Session("select edFileNumber"))
myDataAdapter.F ill(myDataSet, "HospCosts" )
repHospCosts.Da taSource = myDataSet
repHospCosts.Da taMember = "HospCosts"
repHospCosts.Da taBind()

End Sub
Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button2.Click
dtable = myDataSet.Table s("HospCosts" )
drow = dtable.NewRow
drow("SPName") = "Buran"
drow("InvoiceAm ount") = 100
dtable.Rows.Add (drow)
dtable.AcceptCh anges()
Dim subTotal As Double
For Each drow In dtable.Rows
subTotal += drow.Item("Invo iceAmount")
Next
lblSubTotal.Tex t = 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
6976
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 = 'Button'"+ctr.ToString() +"/>")
4
4314
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
4283
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 which is related to the repeater. In the code shown below, if I call Repeater1.Controls.Count in the OnInit (the code fragment was highlighted in yellow) , the viewstate for the repeater will be lost during the postback. You can re-produce this...
0
1214
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 call a function from item template to generate Order and Order items which are returned as a string containing HTML markup tags. Since the Orders and Order items tables are not bound to Repeater I can't add a button template. The button will have...
1
5451
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 fragment of a very simple page that I wrote that will drill down into the displayed item. The result is to be display on the same page so that the user can keep on drilling down:
3
3155
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 expects a DataGridColumn so I instantiated an object of type TemplateColumn that I had hoped I could add a CheckBox to. I soon discovered that the ItemTemplate property of the TemplateColumn class returned an object that had implemented the...
8
3032
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 way I'm going about doing this might be a little off. I'd appreciate some help. Below is the code I have thus far but I'm not sure how to reference the user control within the foreach loop. <asp:Panel ID="pnlRosterProfile" runat="Server" />
6
1598
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 dynamicaly add buttons in the asp page? Totto
2
8172
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 add controls to the templates or how to do the databinding when using the Repeater (or any other templated control) in a CompositeControl. Can somebody please help me here? Thanks. -- Nathan Sokalski njsokalski@hotmail.com...
7
6201
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 something. The buttons show up and post back, but the events do not fire. any help would be appreciated!!! Thank you. protected void gvEntitiesRowDataBound(object sender, GridViewRowEventArgs e) {
0
9721
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10114
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9198
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6880
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4331
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.