473,812 Members | 2,984 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Can I manually add items to a repeater after binding it?

Hello,

I have some data that I'm pulling from an SQL Server, that looks like...

1 jan 05 10
2 jan 05 7
4 jan 05 9
7 jan 05 12

I would like to display this in a repeater, but I want to fill in the
missing days with zeroes, so it would look like...

1 jan 05 10
2 jan 05 7
3 jan 05 0
4 jan 05 9
5 jan 05 0
6 jan 05 0
7 jan 05 12

I have two thoughts about this, either to add the missing rows to the
repeater after it has been bound, or to create a new data table and fill
it with the info from the one pulled from the db, including the missing
days as I go along, and bind the new data to the repeater.

Now the first seems easier, but I can't see any way to do it, although
that could be 'cos I haven't found it yet!!

I have an idea how to do it the second way, but it seems very messy.

Anyone any ideas? TIA

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
4 4965
Your best solution would be to spin through the datatable and add
..NewRow()s as needed to fill in the holes before binding. LIfe will be
easier if you loop from the bottom to the top, since you won't need to
worry about jumping over the new rows as you insert them.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com

Nov 19 '05 #2
>Your best solution would be to spin through the datatable and add
.NewRow()s as needed to fill in the holes before binding. LIfe will be
easier if you loop from the bottom to the top, since you won't need to
worry about jumping over the new rows as you insert them.


Thanks for the suggestion. The way I have it at the moment (written
since posting) is that I pull out a DataReader and whizz through that,
populating a DataTable as I go. Along the way, I look for gaps and add
new rows as needed.

What's the easiest way to go through the DataTable itself? I was trying
to find out how to do this, but couldn't find a clear example. I'm sure
creating a new DataTable and copying the info over into it isn't very
efficient, but it was the only way I could work out how to do it.

Thanks

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #3
You can use a DataAdadapter to fill a table in a DataSet.

DataSet ds = new DataSet();

using (SqlConnection conn = YourConnectionF actory.GetConne ction())
{
SqlCommand objComm = DBHelper.Create StoredProc("You rStoredProcedur e",
conn);
SqlDataAdapter adapt = new SqlDataAdapter( objComm);
adapt.Fill(ds, TableName);
conn.Close();
}

DataTable dt = ds.Tables[0];
for (int a=dt.Rows.Count-1; a>= 0; a--)
{
// check and insert as necessary
}

YourControl.Dat aSource = ds;
YourControl.Dat aBind();
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com

Nov 19 '05 #4
Thanks Jason, that's useful to know.
You can use a DataAdadapter to fill a table in a DataSet.

DataSet ds = new DataSet();

using (SqlConnection conn = YourConnectionF actory.GetConne ction())
{
SqlCommand objComm = DBHelper.Create StoredProc("You rStoredProcedur e",
conn);
SqlDataAdapter adapt = new SqlDataAdapter( objComm);
adapt.Fill(ds, TableName);
conn.Close();
}

DataTable dt = ds.Tables[0];
for (int a=dt.Rows.Count-1; a>= 0; a--)
{
// check and insert as necessary
}

YourControl.Da taSource = ds;
YourControl.Da taBind();
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com


--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #5

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

Similar topics

2
1658
by: Donald Williamson | last post by:
I have a DataReader that I am binding to a Repeater control. In the DataReader, I have two fields: 'Name1' and 'Name2' 'Name1' will always have a person's name. Name2 periodically has a person's name. So the question is if there is a value in 'Name2', I want to display only that name. Otherwise, display 'Name1' Any help on how to do this? Using VS.NET - vb
0
1038
by: MattB | last post by:
I fixed my "can't get the textbox.text" issue by making sure I was only binding the repeater on the first load of the page (if Not IsPostBack). Now I'm adding other controls to my repeater and am having more trouble (like my issues are REPEATING). I've added a RadioButtonList that I'm binding during he OnItemDatabound event of the repeater. The display looks like I'd want it. But when the form is submitted if I use FindControl as I did...
2
2258
by: Antoine | last post by:
I would like to construct my own list of items in a grid/ table/ item list layout but I have a problem. I want to add a sort of index row based on time, such as there might be blank values. Sure the data list I have at the moment is in order, but I would like to have each interval possible, and instead of repeating the row index (the time value) I would like to list it once and then list the items within it (the items associated with...
1
2715
by: Matthew Curiale | last post by:
I have a ddl that is populated in my If Not IsPostBack block in the Page_load event. A repeater is also populated at this time, showing different domains for a website. The ddl contains different price plans that can be selected. My problem is that the user has a choice of being able to update information, or update and create a new domain. In doing either, if the user changes the index of the ddl, I lose all data in the ddl, and my...
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:
1
2297
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small, medium, large), a price, a checkbox to say whether or not the variation is on special offer and a special price. I can pull the values out of the database OK and display them in a repeater. What I want to do is have a set of controls below the...
3
9171
by: Brian | last post by:
Using external XML, I'm trying to build a quiz, but I can't seem to specify the DataSource for the RadioButtonList within a Repeater ItemTemplate. I've tried a number of approaches, but I haven't really had any success. I'm pretty sure I should be casting my XPathSelect() call to something so I can get at its attributes. This seems like it should be easy, and maybe I'm missing something obvious. Does anyone have any ideas? Here is the...
4
4926
by: Brad Baker | last post by:
I'm going a little crazy :) I'm trying to bind a repeater control to a dataset on page load using the following code: if (Request.QueryString != null) { string customerid = Request.QueryString; //open connection SqlConnection m_conn = new SqlConnection("Server=server; Database=database; UId=username; Pwd=password");
4
5767
by: adiel_g | last post by:
I am trying to loop through a repeater to retrieve a dataitem field but am getting a NullReferenceException. I can find a checkbox control but cannot find a dataitem field. Here is the code that is looping through the repeater: Dim rc As RepeaterItemCollection = rptReport.Items Dim ri As RepeaterItem Dim chkSelected As System.Web.UI.WebControls.CheckBox Dim customer As String
0
9734
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
10664
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10404
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
10417
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
10139
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...
1
7677
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5704
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3881
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3029
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.