473,624 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y Adding An Item To The DataList

Hi all,
I've a DataList control and it's DataBound by a SqlDataReader.. .
The Reader returns say 3 records and as expected the datalist shows 3 rows.
What i want to do is to add another extra Record (which is not neccesarily a
database record..) but it'll be shown up as an ordinary item in the datalist
rendered as an Item or AlternatingItem ...
Is there a way to do this?

Thanks
Nov 15 '05 #1
6 4302
Try to fill DataList with a loop and then add the extra record.
Or override PreRender event of DataList and add the extra record.
Hope this helps.
Nov 15 '05 #2
Thank you,
That's what i'm avoiding to do... (but seems like the only way i have .. )
Why isn't it allowed myDataList.Item s.Add(new DataListItem(). ..... ) or
smtg. like this..
??
Any other ideas?

"Bench Wang" <be*******@sohu .com> wrote in message
news:Oy******** ******@tk2msftn gp13.phx.gbl...
Try to fill DataList with a loop and then add the extra record.
Or override PreRender event of DataList and add the extra record.
Hope this helps.

Nov 15 '05 #3
Umut,
For a System.Web.UI.W ebControls.Drop DownList, I use something similar to:

Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextFie ld = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Inser t(0, New ListItem("<sele ct item>", ""))

I use the above in the Page Load event, which adds the <select item> to the
top of the drop down list. Notice that I call DataBind before I add the
extra item.

I would expect a DataList to work the same way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:ud******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi all,
I've a DataList control and it's DataBound by a SqlDataReader.. .
The Reader returns say 3 records and as expected the datalist shows 3 rows. What i want to do is to add another extra Record (which is not neccesarily a database record..) but it'll be shown up as an ordinary item in the datalist rendered as an Item or AlternatingItem ...
Is there a way to do this?

Thanks

Nov 15 '05 #4
Yes, while this works great for the DropDownList,
System.Web.UI.W ebControls.Data List doesn't allow sucha method like Insert...
I mean ther's no method like Insert or Add (or am i missing something?)

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Umut,
For a System.Web.UI.W ebControls.Drop DownList, I use something similar to:

Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextFie ld = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Inser t(0, New ListItem("<sele ct item>", ""))

I use the above in the Page Load event, which adds the <select item> to the top of the drop down list. Notice that I call DataBind before I add the
extra item.

I would expect a DataList to work the same way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:ud******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi all,
I've a DataList control and it's DataBound by a SqlDataReader.. .
The Reader returns say 3 records and as expected the datalist shows 3 rows.
What i want to do is to add another extra Record (which is not

neccesarily a
database record..) but it'll be shown up as an ordinary item in the

datalist
rendered as an Item or AlternatingItem ...
Is there a way to do this?

Thanks


Nov 15 '05 #5
Umut,
Doh! I don't see an Add or Insert on the DataListItemCol lection either.

Curious that they are different, must be some reason. (shrug)

Two options I would consider instead then.

1. Use the SqlDataReader to populate a DataTable, add your row to the
DataTable, then bind to the DataTable.
2. Create a 'Proxy' Data reader that returns the values out of a contained
SqlDataReader, plus the extra row. This class would implement the
IDataReader, IDataRecord, IDisposable, and IEnumerable interfaces.
Delegating most calls to the contained SqlDataReader, however it would
return one or two records first or last... Similar to how the
System.IO.Strea m classes work, where you can chain one stream to second
stream chained to a third stream...

I haven't done a lot with DataLists, maybe there is an easier way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes, while this works great for the DropDownList,
System.Web.UI.W ebControls.Data List doesn't allow sucha method like Insert... I mean ther's no method like Insert or Add (or am i missing something?)

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Umut,
For a System.Web.UI.W ebControls.Drop DownList, I use something similar to:
Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextFie ld = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Inser t(0, New ListItem("<sele ct item>", ""))

I use the above in the Page Load event, which adds the <select item> to

the
top of the drop down list. Notice that I call DataBind before I add the
extra item.

I would expect a DataList to work the same way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:ud******** *******@TK2MSFT NGP09.phx.gbl.. .
Hi all,
I've a DataList control and it's DataBound by a SqlDataReader.. .
The Reader returns say 3 records and as expected the datalist shows 3

rows.
What i want to do is to add another extra Record (which is not

neccesarily
a
database record..) but it'll be shown up as an ordinary item in the

datalist
rendered as an Item or AlternatingItem ...
Is there a way to do this?

Thanks



Nov 15 '05 #6
Jay, thanks. i'm going to try your suggestions..
"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:uE******** ******@TK2MSFTN GP10.phx.gbl...
Umut,
Doh! I don't see an Add or Insert on the DataListItemCol lection either.

Curious that they are different, must be some reason. (shrug)

Two options I would consider instead then.

1. Use the SqlDataReader to populate a DataTable, add your row to the
DataTable, then bind to the DataTable.
2. Create a 'Proxy' Data reader that returns the values out of a contained
SqlDataReader, plus the extra row. This class would implement the
IDataReader, IDataRecord, IDisposable, and IEnumerable interfaces.
Delegating most calls to the contained SqlDataReader, however it would
return one or two records first or last... Similar to how the
System.IO.Strea m classes work, where you can chain one stream to second
stream chained to a third stream...

I haven't done a lot with DataLists, maybe there is an easier way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes, while this works great for the DropDownList,
System.Web.UI.W ebControls.Data List doesn't allow sucha method like

Insert...
I mean ther's no method like Insert or Add (or am i missing something?)

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in

message
news:%2******** *******@TK2MSFT NGP11.phx.gbl.. .
Umut,
For a System.Web.UI.W ebControls.Drop DownList, I use something similar to:
Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextFie ld = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Inser t(0, New ListItem("<sele ct item>", ""))

I use the above in the Page Load event, which adds the <select item> to
the
top of the drop down list. Notice that I call DataBind before I add

the extra item.

I would expect a DataList to work the same way.

Hope this helps
Jay

"Umut K." <uk*****@yahoo. com> wrote in message
news:ud******** *******@TK2MSFT NGP09.phx.gbl.. .
> Hi all,
> I've a DataList control and it's DataBound by a SqlDataReader.. .
> The Reader returns say 3 records and as expected the datalist shows 3 rows.
> What i want to do is to add another extra Record (which is not

neccesarily
a
> database record..) but it'll be shown up as an ordinary item in the
datalist
> rendered as an Item or AlternatingItem ...
> Is there a way to do this?
>
> Thanks
>
>



Nov 15 '05 #7

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

Similar topics

6
9111
by: Umut K. | last post by:
Hi all, I've a DataList control and it's DataBound by a SqlDataReader... The Reader returns say 3 records and as expected the datalist shows 3 rows. What i want to do is to add another extra Record (which is not neccesarily a database record..) but it'll be shown up as an ordinary item in the datalist rendered as an Item or AlternatingItem ... Is there a way to do this? Thanks
0
1431
by: john | last post by:
I would like to programmatically (from VB.NET or C#), manage items in the windows explorer 'folder' context menu (right click menu). I need an entry to be able to pass the folder path to my application. If I can configure this using the .NET framework then that would be ideal, using Win32 a close second. Modifying the registry would be ok but not sure how safe this would be on future versions of windows. Any help much appreciated.
2
1414
by: joyce85 | last post by:
hai i had 1 prblm of adding item to listbox.. but i succeeded that with the help of datasouce.. but i am not able to modify items in listbox..how can i do that my coding are
2
15065
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
6
10107
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
0
8236
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
8621
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
8335
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
8475
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
7159
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...
1
6110
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
5563
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
4079
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
1785
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.