adding new rows 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

0
buran
3/29/2005 10:37:27 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
753 Views

Similar Articles

[PageSpeed] 36

How are you retaining the dataset across postbacks?  You have to use the Session or Cache to store the dataset across multiple postbacks, or recreate it as needed.

Brian


Brian

"Trust in the Lord and do what is good; dwell in the land and live securely. Take delight in the Lord, and He will give you your heart's desires" (Psalm 37: 3-4).
0
bmains
3/29/2005 12:48:42 PM

Thanks, I solved the problem. I was using:

If Not Page.IsPostBack Then

      LoadHospCosts()

End If

I moved it outside the if clause and it worked. Thank you.

0
buran
3/29/2005 1:09:33 PM
Reply:

Similar Artilces:

Add new controls to a gridview row; when editing that row using the edit row feature in the gridview control.
Hi all  I have a questions that looks hard / complex to me, and i know you can help me in this. Q {  I have row in a Gridview and i have an edit option to it. I press the edit button, to edit the values in that row and update data all the way back to the database. Now when i press the edit button, i want a drop down list to be displayed that contain values for a particular field in my grid view. (for now only plain text boxes appear.) } I hope you understand my question, all i need to do is replace the text box controls with a dropdown list when i am editing a row in ...

Adding a Label control inside a Repeater control
I am editing a web application that is accessed by customers in 3 different countries.  As such, the text on the website is different depending on what country it is accessed from. The way I have implemented this, is that I have one aspx page.  All the text that is consistent across all countries is typed directly into this page.  However, the text that changes is placed in <asp:label> tags, and we determine what text is to be displayed at runtime I have run into an issue though, because some of the "dynamic" text needs to be placed inside an <asp:repeater> contr...

Repeater control in another repeater control
Hi, I want Repeater control in another repeater control but it is not working Code : <asp:Repeater ID=CourseMaster Runat=server > <ItemTemplate> <table border=0 cellpadding=0 cellspacing=0 style="font-family:tahoma;font-size:12"> <tr> <td >&nbsp;<b</b></td> </tr> <tr> <td> <asp:repeater ID="CourseDetails" Runat=server> <ItemTemplate> <tab...

New .Net Controls Added
www.TechnicalVideos.Net is now offering new .Net Controls for you to download free with the purchase of a 3 month or longer subscription to our site. So for $19.99 you will now get over 125 videos along with .Net controls and their source code. www.TechnicalVideos.Net ...

Adding Event Handler to Child Control in Repeater Control
I have a user control which has links buttons as children controls. I use this control to show the parent and child data.<asp:Repeater id="Repeater" runat="server" OnItemDataBound="Repeater_ItemDataBound"> <ItemTemplate> <asp:Panel id="Panel" runat="server"> <asp:Label id="Name" runat="server" Font-Bold></asp:Label> <div class="Small"> <asp:Panel id="EditPanel" runat="server"> <asp:Label ID="lblids" runat="server" Visible...

Problem How to get a Control Id When i am adding a new control to my webpage
Hi All, I am doing a new web site in Asp.2.0, here i am using masterpages,webparts, and WebUserControls. what my problem is i did some webuser controls like Announcements, Categories, Links, Like that. so now i am adding these controls in my webparts where ever i need. so the problem is a single control i am using 2 to 3 times in a page. so at that time i need a id for that control. I know when i am adding a control then it has an id. so how to know that id. please help me in this regard.Regards,Ram Mohan Rao Adduri,Techinical Associate,eSymbiosisHyderabad.Mobile: 9490118545...

Repeater control
Hi all I'm binding a Repeater control to a dataset.  for each row in the dataset I then generate a textbox and a label.  the label displays the title of the item in the datarow fo the dataset.  the textbox should be used so that the users can enter a criteria against the item. When the user submits the page, I need to retrieve the values entered in the textboxes and match them back up with the appropriate item from the dataset. I can't see anyway of doing this? here's some code...the repeater sits inside a table which is why there are <tr> and <td> ...

Adding a dynamic reference to an image control from a repeater control
Hi  I'm using a repeater control, and within it I have an image control. I want to set the imageUrl property of the image control to a reference from the repeater - I hope I'm explaining this right! ;)  This is what I've tried (to help illustrate), but alas, it's not working :( <asp:Image ID="Image1" runat="server" ImageUrl="~/images/<%#DataBinder.Eval(Container.DataItem, "productImage")%>.gif" /> Thanks for any helpRichard Try <asp:Image ID="Image1" runat="server" ImageUrl='~/image...

moving to a new row in repeater control
I am using Repeater to display record in a table with each record going in one column but i want to change to new line after lets say 5 records. Is there any Repeater feature that i can use to do that. Hi roomy, Repeater control doesn't have this function. I suggest you can use DataList control instead with setting RepeatDirection="Horizontal" RepeatColumns="5". Or you can try ListView with setting GroupTemplate in it: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.grouptemplate.aspx Thanks,Qin Dian TangMicrosoft Online Community Suppor...

Controlling a variable numbers of controls dynamically added to a user control
 Ok, thinking caps on people, this has been causing me grief for a couple of days now. I have an .aspx page which contains various user controls housed in an Accordion control from the Ajax Toolkit and lots of UpdatePanels, these user controls all interact with each other through the parent page, e.g clicking buttons in one control effects visibility of other controls. Two of these controls contain just a series of ImageButtons. In the first of these controls the ImageButtons are generated in the page_load method and added to a panel using Panel.Controls.Add(ImageButtonCont...

adding / deleting table rows, and accessing controls within added rows
Hi everyone,I would like to know what is a good and simple way to achieve this using asp.net.  Basically i would like the ability to add and delete rows, preferably table rows.  Against each row is its delete button, hitting it will delete the corresponding row.  There is only 1 Add button to add a new row.  In each row, there are say 2 textboxes.  When i hit, say a calculate button, i wish to be able to access all the available textboxes in all the available rows in the event handler, and say just output a sum.If GridView is suggested, could you please explain why i...

Adding a new row of controls on button click
Hi all,In a site I'm currently writing, I have a page in which users can add entries to the database.  The entries are very simple, consisting of selections from three drop down lists.In order to make it easier on the user, I would prefer to allow multiple entries to be created on the same page.  To keep the page clutter down, I want the user to be able to click on a button to add another row for entry creation on the same page.For a visual example of what I mean, check out this link. At the very bottom under "advanced search using boolean charts" is exactly what I wa...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Composite Control
I have created a modal popup composite control in hopes to reduce the amount of code on the in-line code to do modal popups.  Everything works just fine, except when I try to add user controls to the control.  I add a user control to the form control on OnInit, OnLoad, etc.  No matter what I do, the modal does not show up.  On this control, wire up the ModalPopupButtonClicked event and call the Show method to open the modal.  Anyways, can anyone tell me why this control won't work with user controls when I add them?    using System; ...

Web resources about - adding new rows to the repeater control - asp.net.presentation-controls

Repeaters - Wikipedia, the free encyclopedia
Kyle Halsted, Sonia Logan, and Michael Weeks are inmates at a rehabilitation facility. Bob Simpson, the administrator, tasks them with apologizing ...

Animal Repeater Memory Game HD Free Lite - for iPad for iPad on the iTunes App Store
Get Animal Repeater Memory Game HD Free Lite - for iPad on the App Store. See screenshots and ratings, and read customer reviews.

Consumers warned to beware of illegal mobile phone repeaters
Use of devices sold online as legitimate solution is in fact dangerous and can land you in jail, regulator warns.

Grim repeater: HIV on the rise
CANDLES flicker in the chilly night air as Jesse Hooper appears on the giant cinema screen overlooking Melbourne&#8217;s Federation Square. He&#8217;s ...

Telstra suspects underbelly of illegal repeaters
'Tens' busted each year. Telstra engineers suspect a "vast" undercurrent of illegal repeaters are causing issues for the carrier's Next G mobile ...

Hands on: Cel-Fi mobile repeater
If your home is a mobile blackspot then a Cel-Fi mobile repeater might help you stay connected.

Amped Wireless R20000G, SR20000G, and UA2000: Routers, Repeaters, and Adapters
... and throughput when pointed at your wireless router/access point. Rounding out the review, Amped sent a third product, their SR20000G repeater, ...

Photon heralds entanglement in new quantum repeater
... For ordinary electrical wires (such those used for ethernet), signals can travel long distances because they're boosted by means of repeaters ...

Celebrity Rehab Repeaters
Kate Middleton Bikini Photos 50 Shades of Grey Hollywood Couples Red Carpet The Kardashians Best Dressed Hot Bodies Celebrity Kids News Sightings ...

Computer networking: wireless networks (wifi), routers, repeaters & more - CNET Reviews
Computer networking reviews and ratings, video reviews, user opinions, most popular network hardware, wireless network buying guides, prices, ...

Resources last updated: 12/10/2015 12:19:31 PM