R
ree321
I have a linkbutton which is added to a column in a datagrid
dynamically using a template I created. When I change the data in it
by not databinding and then when I later retreive the data from the
control after a post back it goes back to the value which was
dynamically bounded.
I have set up similar process with a checkbox template and it remebers
the value.
Are Linkbuttons not capable of this? and should I use something else?
Here is the code I used to change the values in the linkbutton:
Dim lbtn As LinkButton = dgi.Cells(colNum).Controls(0)
lbtn.Text = "Hello"
lbtn.CommandArgument = 1001
When the page has been rendered it shows up as "Hello". But then on a
post back I try and retreieve the data
userInputValues(i) = CType(e.Item.Cells(i).Controls(0),
LinkButton).Text
It has the old value.
Here is the Itemplate code
Public Class TemplateEditLinkButton
Implements ITemplate
Private ColName As String
Private SecondColName As String
Private SecondColAsDisplay As Boolean
Public Sub New(ByVal aColName As String, ByVal aSecondColName As
String, ByVal aSecondColAsDisplay As Boolean)
ColName = aColName
SecondColName = aSecondColName
SecondColAsDisplay = aSecondColAsDisplay 'so the secoond col
will be the lbtn Text, and first column will be the text
End Sub
Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Dim lbtn As LinkButton = New LinkButton
AddHandler lbtn.DataBinding, AddressOf Me.BindLinkButton
container.Controls.Add(lbtn)
End Sub
Sub BindLinkButton(ByVal s As Object, ByVal e As EventArgs)
Dim lbtn As LinkButton = s
Dim dgi As DataGridItem
dgi = CType(lbtn.NamingContainer, DataGridItem)
Dim textCol As String = ColName
Dim argCol As String = SecondColName
If SecondColAsDisplay Then 'switch it around
textCol = SecondColName
argCol = ColName
End If
If Not dgi.DataItem(textCol) Is DBNull.Value Then
lbtn.Text = dgi.DataItem(textCol)
Else
lbtn.Text = "[Empty]"
End If
lbtn.CommandArgument = dgi.DataItem(argCol)
End Sub
End Class
dynamically using a template I created. When I change the data in it
by not databinding and then when I later retreive the data from the
control after a post back it goes back to the value which was
dynamically bounded.
I have set up similar process with a checkbox template and it remebers
the value.
Are Linkbuttons not capable of this? and should I use something else?
Here is the code I used to change the values in the linkbutton:
Dim lbtn As LinkButton = dgi.Cells(colNum).Controls(0)
lbtn.Text = "Hello"
lbtn.CommandArgument = 1001
When the page has been rendered it shows up as "Hello". But then on a
post back I try and retreieve the data
userInputValues(i) = CType(e.Item.Cells(i).Controls(0),
LinkButton).Text
It has the old value.
Here is the Itemplate code
Public Class TemplateEditLinkButton
Implements ITemplate
Private ColName As String
Private SecondColName As String
Private SecondColAsDisplay As Boolean
Public Sub New(ByVal aColName As String, ByVal aSecondColName As
String, ByVal aSecondColAsDisplay As Boolean)
ColName = aColName
SecondColName = aSecondColName
SecondColAsDisplay = aSecondColAsDisplay 'so the secoond col
will be the lbtn Text, and first column will be the text
End Sub
Public Sub InstantiateIn(ByVal container As Control) Implements
ITemplate.InstantiateIn
Dim lbtn As LinkButton = New LinkButton
AddHandler lbtn.DataBinding, AddressOf Me.BindLinkButton
container.Controls.Add(lbtn)
End Sub
Sub BindLinkButton(ByVal s As Object, ByVal e As EventArgs)
Dim lbtn As LinkButton = s
Dim dgi As DataGridItem
dgi = CType(lbtn.NamingContainer, DataGridItem)
Dim textCol As String = ColName
Dim argCol As String = SecondColName
If SecondColAsDisplay Then 'switch it around
textCol = SecondColName
argCol = ColName
End If
If Not dgi.DataItem(textCol) Is DBNull.Value Then
lbtn.Text = dgi.DataItem(textCol)
Else
lbtn.Text = "[Empty]"
End If
lbtn.CommandArgument = dgi.DataItem(argCol)
End Sub
End Class