C
Chris
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
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