473,500 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmatically 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 4286
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.Items.Add(new DataListItem()...... ) or
smtg. like this..
??
Any other ideas?

"Bench Wang" <be*******@sohu.com> wrote in message
news:Oy**************@tk2msftngp13.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.WebControls.DropDownList, I use something similar to:

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

DataBind()

lst.Items.Insert(0, New ListItem("<select 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***************@TK2MSFTNGP09.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.WebControls.DataList 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********@email.msn.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Umut,
For a System.Web.UI.WebControls.DropDownList, I use something similar to:

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

DataBind()

lst.Items.Insert(0, New ListItem("<select 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***************@TK2MSFTNGP09.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 DataListItemCollection 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.Stream 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***************@TK2MSFTNGP09.phx.gbl...
Yes, while this works great for the DropDownList,
System.Web.UI.WebControls.DataList 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********@email.msn.com> wrote in message news:%2***************@TK2MSFTNGP11.phx.gbl...
Umut,
For a System.Web.UI.WebControls.DropDownList, I use something similar to:
Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextField = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Insert(0, New ListItem("<select 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***************@TK2MSFTNGP09.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********@email.msn.com> wrote in message
news:uE**************@TK2MSFTNGP10.phx.gbl...
Umut,
Doh! I don't see an Add or Insert on the DataListItemCollection 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.Stream 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***************@TK2MSFTNGP09.phx.gbl...
Yes, while this works great for the DropDownList,
System.Web.UI.WebControls.DataList 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********@email.msn.com> wrote in

message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Umut,
For a System.Web.UI.WebControls.DropDownList, I use something similar to:
Dim Data As DataSet
Dim lst As DropDownList
lst.DataMember = "MyMember"
lst.DataTextField = "FieldName"
lst.DataSrouce = Data

DataBind()

lst.Items.Insert(0, New ListItem("<select 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***************@TK2MSFTNGP09.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
9090
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...
0
1412
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...
2
1401
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
15042
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...
6
10096
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...
0
7136
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,...
0
7182
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,...
0
7232
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...
0
7397
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...
1
4923
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...
0
3110
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...
0
3106
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1430
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 ...
1
672
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.