473,795 Members | 2,425 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button in Datalist Footer Error...

Hi Folks,

well I have this "small" problem with the footertemplate in a
datalist.
I added a button and a textbox to update the db with the given String
of the Textbox.
I already searched for it and know now, that I have to place the
handling in Itemcreated. So when I click on the button everything is
fine except when the sub "createSubj ect" is called, then I get an
"Object reference not set" error.
This occurs when I try to get the value of the Textbox.

Is this in general the best approach for using a button with some
commands in a datalist Footer or am I just missing something...

Any Links, references, help would be really appreciated as this whole
datalist thing is driving me nuts...

Thanks in advance,
Chris

Below is my Code

Private Sub dlsNewSubject_I temCreated(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
dlsNewSubject.I temCreated
If e.Item.ItemType = ListItemType.Fo oter Then
Dim cmdCreateSubjec t As Button =
CType(e.Item.Fi ndControl("cmdC reateSubject"), Button)
AddHandler cmdCreateSubjec t.Click, AddressOf CreateSubject

End If
End Sub
Public Sub CreateSubject(B yVal sender As System.Object, ByVal e As
System.EventArg s)
Dim dlSubject As DataList
Dim NewSubjectName As String
NewSubjectName = CType(dlSubject .FindControl("t xtNewSubject"),
TextBox).Text
....
Do the database Stuff here
....
End Sub
Nov 18 '05 #1
3 1733
Instead of attaching a command handler to this button, set its commandname
property, and check for it during the ItemCommand event. If the item type is
footer, you should be able to use FindControl on the item to find your
textbox.

"Chris" <de*****@gmx.de > wrote in message
news:c9******** *************** ***@posting.goo gle.com...
Hi Folks,

well I have this "small" problem with the footertemplate in a
datalist.
I added a button and a textbox to update the db with the given String
of the Textbox.
I already searched for it and know now, that I have to place the
handling in Itemcreated. So when I click on the button everything is
fine except when the sub "createSubj ect" is called, then I get an
"Object reference not set" error.
This occurs when I try to get the value of the Textbox.

Is this in general the best approach for using a button with some
commands in a datalist Footer or am I just missing something...

Any Links, references, help would be really appreciated as this whole
datalist thing is driving me nuts...

Thanks in advance,
Chris

Below is my Code

Private Sub dlsNewSubject_I temCreated(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
dlsNewSubject.I temCreated
If e.Item.ItemType = ListItemType.Fo oter Then
Dim cmdCreateSubjec t As Button =
CType(e.Item.Fi ndControl("cmdC reateSubject"), Button)
AddHandler cmdCreateSubjec t.Click, AddressOf CreateSubject

End If
End Sub
Public Sub CreateSubject(B yVal sender As System.Object, ByVal e As
System.EventArg s)
Dim dlSubject As DataList
Dim NewSubjectName As String
NewSubjectName = CType(dlSubject .FindControl("t xtNewSubject"),
TextBox).Text
...
Do the database Stuff here
...
End Sub

Nov 18 '05 #2
Hi Rick,

thanks for the reply. I tested your suggestion and put the Commandname
in the aspx page and the code as well in the Itemcommand event but it
doesn't fire there either, in fact if I debug it, the ItemCommand
doesn't even get touched.
Do I have to make a reference out of the ItemCreated to the
ItemCommand in some way and if so how can I do that?

Maybe it's just me, but I thought a button in the Datalist
footer/header must be a common thing, but yet I haven't found any
example that worked for me so far.

cheers,
Chris
"Rick Spiewak" <ri*********@mi ndspring.com> wrote in message news:<OM******* *******@TK2MSFT NGP10.phx.gbl>. ..
Instead of attaching a command handler to this button, set its commandname
property, and check for it during the ItemCommand event. If the item type is
footer, you should be able to use FindControl on the item to find your
textbox.

"Chris" <de*****@gmx.de > wrote in message
news:c9******** *************** ***@posting.goo gle.com...
Hi Folks,

well I have this "small" problem with the footertemplate in a
datalist.
I added a button and a textbox to update the db with the given String
of the Textbox.
I already searched for it and know now, that I have to place the
handling in Itemcreated. So when I click on the button everything is
fine except when the sub "createSubj ect" is called, then I get an
"Object reference not set" error.
This occurs when I try to get the value of the Textbox.

Is this in general the best approach for using a button with some
commands in a datalist Footer or am I just missing something...

Any Links, references, help would be really appreciated as this whole
datalist thing is driving me nuts...

Thanks in advance,
Chris

Below is my Code

Private Sub dlsNewSubject_I temCreated(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
dlsNewSubject.I temCreated
If e.Item.ItemType = ListItemType.Fo oter Then
Dim cmdCreateSubjec t As Button =
CType(e.Item.Fi ndControl("cmdC reateSubject"), Button)
AddHandler cmdCreateSubjec t.Click, AddressOf CreateSubject

End If
End Sub
Public Sub CreateSubject(B yVal sender As System.Object, ByVal e As
System.EventArg s)
Dim dlSubject As DataList
Dim NewSubjectName As String
NewSubjectName = CType(dlSubject .FindControl("t xtNewSubject"),
TextBox).Text
...
Do the database Stuff here
...
End Sub

Nov 18 '05 #3
"It works on my machine" said the developer <g>.

Here's the .aspx part:
<asp:DataList id="DataList1" style="Z-INDEX: 105; LEFT: 360px; POSITION:
absolute; TOP: 276px" runat="server">
<FooterTemplate >
<asp:Button id="Button3" runat="server" Text="Button"
CommandName="Cr eateSubject"></asp:Button>
<asp:TextBox id="TextBox2" runat="server"> </asp:TextBox>
</FooterTemplate>
<ItemTemplate >
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
</ItemTemplate>
</asp:DataList>

Here's the code-behind piece I used to test it:

Private Sub DataList1_ItemC ommand(ByVal source As Object, ByVal e As
System.Web.UI.W ebControls.Data ListCommandEven tArgs) Handles
DataList1.ItemC ommand
Dim i As Integer = 0
End Sub

Private Sub btnTestDataList _Click(ByVal sender As System.Object, ByVal e
As System.EventArg s) Handles btnTestDataList .Click
Dim al As New ArrayList
al.Add("One")
al.Add("Two")
Me.DataList1.Da taSource = al
Me.DataList1.Da taBind()
End Sub

putting a breakpoint on the "dim i as integer" line, I see:
?e.CommandName
"CreateSubj ect"

"Chris" <de*****@gmx.de > wrote in message
news:c9******** *************** ***@posting.goo gle.com...
Hi Rick,

thanks for the reply. I tested your suggestion and put the Commandname
in the aspx page and the code as well in the Itemcommand event but it
doesn't fire there either, in fact if I debug it, the ItemCommand
doesn't even get touched.
Do I have to make a reference out of the ItemCreated to the
ItemCommand in some way and if so how can I do that?

Maybe it's just me, but I thought a button in the Datalist
footer/header must be a common thing, but yet I haven't found any
example that worked for me so far.

cheers,
Chris
"Rick Spiewak" <ri*********@mi ndspring.com> wrote in message

news:<OM******* *******@TK2MSFT NGP10.phx.gbl>. ..
Instead of attaching a command handler to this button, set its commandname property, and check for it during the ItemCommand event. If the item type is footer, you should be able to use FindControl on the item to find your
textbox.

"Chris" <de*****@gmx.de > wrote in message
news:c9******** *************** ***@posting.goo gle.com...
Hi Folks,

well I have this "small" problem with the footertemplate in a
datalist.
I added a button and a textbox to update the db with the given String
of the Textbox.
I already searched for it and know now, that I have to place the
handling in Itemcreated. So when I click on the button everything is
fine except when the sub "createSubj ect" is called, then I get an
"Object reference not set" error.
This occurs when I try to get the value of the Textbox.

Is this in general the best approach for using a button with some
commands in a datalist Footer or am I just missing something...

Any Links, references, help would be really appreciated as this whole
datalist thing is driving me nuts...

Thanks in advance,
Chris

Below is my Code

Private Sub dlsNewSubject_I temCreated(ByVa l sender As Object, ByVal e
As System.Web.UI.W ebControls.Data ListItemEventAr gs) Handles
dlsNewSubject.I temCreated
If e.Item.ItemType = ListItemType.Fo oter Then
Dim cmdCreateSubjec t As Button =
CType(e.Item.Fi ndControl("cmdC reateSubject"), Button)
AddHandler cmdCreateSubjec t.Click, AddressOf CreateSubject

End If
End Sub
Public Sub CreateSubject(B yVal sender As System.Object, ByVal e As
System.EventArg s)
Dim dlSubject As DataList
Dim NewSubjectName As String
NewSubjectName = CType(dlSubject .FindControl("t xtNewSubject"),
TextBox).Text
...
Do the database Stuff here
...
End Sub

Nov 18 '05 #4

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

Similar topics

4
5481
by: Kaung Htut O via DotNetMonster.com | last post by:
Hi to all Is there a way to access Datalist Footer's Control properties from outside of datalist event. Pls note that I mean not a datagrid, only for datalist. Thanks Kaung Htut Oo
2
5235
by: Leo Duran | last post by:
Hi, I am working on an app right now that makes extensive use of the DataList control. I chose the DataList because I need to do multi row formatting. I am using it like so.
1
1707
by: David W. Simmonds | last post by:
I have a Button in a DataList Footer. I add the click event like this: void Item_DataBound(Object sender, DataListItemEventArgs e) { if(e.Item.ItemType == ListItemType.Footer) { Button ctlSave = (Button)e.Item.FindControl("ctlSave"); ctlSave.Click += new EventHandler(ctlSave_Click); } }
2
8738
by: Chris Fink | last post by:
This should be relatively simple but I am unable to find an asp:button tag in a datalist footer. I have tried it numerous ways including the FindControl method from the many events that the DataList exposes and the result is always null (I've determined the OnItemDataBound event will not find the footer controls). I understand that I have to navigate the datalist object tree, but I feel like it is a guessing game and am hesitant to do it...
5
3872
by: Martman | last post by:
First here is my goal: When a datalist is rendered to a page and you use the <itemtemplate> the datalist automatically prints a <tr> <td> start and end tags. Now this may not be too bad but I have run into a situation repeatedly with the designing factor of a datalist. Most of the time when I use a datalist I utilize the header, item, and footer templates to build a custom table. However, utilizing the simple example below you will...
6
2191
by: tshad | last post by:
I need to get to a status label I have on my footer section of my datalist. There is no event happening that would go to the footer. I am just doing some processing and want to update the label on the footer. At the moment, I go through the dataListItems like so: for each oItem as DataListItem in DataList1.Items trace.warn("inside for loop oItem type = " & oItem.itemType.ToString())
1
1409
by: jagdishl | last post by:
Hi: I have a datalist which is populated dynamically based on a query.I have to place a submit button after datalist (not in the footer template) so that after pressing the submit button a final update is made to the database.The datalist may at times be very long.i was wondering how I could place this submit button in the design page.I would really be grateful if you could point out to sample codes. Thank you. Jagdish.l
2
1419
by: rhyme2ri2 | last post by:
Hi!! I'm using asp.net 1.1 I have a datalist which gets dynamic data which is of unbound size may be small sometimes and may be very very long sometimes....... Whatever the size of data may be there is a button at the end of datalist...... When data is large the datalist text overlaps the button..... so what i did is added the button to the footer template of datalist!!!!!!!! But due to this the button stopped working..... It's...
1
3776
by: Arielle | last post by:
Background: I have a generated datalist to display information and I need to add the capability to have a button (Edit button) so that users can change the information. I'm sure once I figure it out I'll smack myself on the head for being so stupid but I feel as though right now I'm chasing my tail and want to see if some of yall can point me in a better direction. Initiation public class GroupDetail : WebPart { //... DataList...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10437
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
10214
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
10164
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
10001
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
7538
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
6780
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();...
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
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.