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 "createSubject" 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_ItemCreated(ByVal sender As Object, ByVal e
As System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlsNewSubject.ItemCreated
If e.Item.ItemType = ListItemType.Footer Then
Dim cmdCreateSubject As Button =
CType(e.Item.FindControl("cmdCreateSubject"), Button)
AddHandler cmdCreateSubject.Click, AddressOf CreateSubject
End If
End Sub
Public Sub CreateSubject(ByVal sender As System.Object, ByVal e As
System.EventArgs)
Dim dlSubject As DataList
Dim NewSubjectName As String
NewSubjectName = CType(dlSubject.FindControl("txtNewSubject"),
TextBox).Text
....
Do the database Stuff here
....
End Sub 3 1718
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.google.c om... 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 "createSubject" 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_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlsNewSubject.ItemCreated If e.Item.ItemType = ListItemType.Footer Then Dim cmdCreateSubject As Button = CType(e.Item.FindControl("cmdCreateSubject"), Button) AddHandler cmdCreateSubject.Click, AddressOf CreateSubject
End If End Sub
Public Sub CreateSubject(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim dlSubject As DataList Dim NewSubjectName As String NewSubjectName = CType(dlSubject.FindControl("txtNewSubject"), TextBox).Text ... Do the database Stuff here ... End Sub
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*********@mindspring.com> wrote in message news:<OM**************@TK2MSFTNGP10.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.google.c om... 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 "createSubject" 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_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlsNewSubject.ItemCreated If e.Item.ItemType = ListItemType.Footer Then Dim cmdCreateSubject As Button = CType(e.Item.FindControl("cmdCreateSubject"), Button) AddHandler cmdCreateSubject.Click, AddressOf CreateSubject
End If End Sub
Public Sub CreateSubject(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim dlSubject As DataList Dim NewSubjectName As String NewSubjectName = CType(dlSubject.FindControl("txtNewSubject"), TextBox).Text ... Do the database Stuff here ... End Sub
"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="CreateSubject"></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_ItemCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataListCommandEventArgs ) Handles
DataList1.ItemCommand
Dim i As Integer = 0
End Sub
Private Sub btnTestDataList_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnTestDataList.Click
Dim al As New ArrayList
al.Add("One")
al.Add("Two")
Me.DataList1.DataSource = al
Me.DataList1.DataBind()
End Sub
putting a breakpoint on the "dim i as integer" line, I see:
?e.CommandName
"CreateSubject"
"Chris" <de*****@gmx.de> wrote in message
news:c9**************************@posting.google.c om... 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*********@mindspring.com> wrote in message
news:<OM**************@TK2MSFTNGP10.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.google.c om... 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 "createSubject" 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_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles dlsNewSubject.ItemCreated If e.Item.ItemType = ListItemType.Footer Then Dim cmdCreateSubject As Button = CType(e.Item.FindControl("cmdCreateSubject"), Button) AddHandler cmdCreateSubject.Click, AddressOf CreateSubject
End If End Sub
Public Sub CreateSubject(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim dlSubject As DataList Dim NewSubjectName As String NewSubjectName = CType(dlSubject.FindControl("txtNewSubject"), TextBox).Text ... Do the database Stuff here ... End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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
|
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.
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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,...
|
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...
|
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...
|
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,...
| |