B
Burak Gunay
Hello,
I am trying to write the dynamic code behind version of this code in
the data behind:
<asp:TemplateColumn HeaderStyle-ForeColor="white" Headertext="ID">
<ItemTemplate>
<asp:LinkButton ID="lnkCopyPnl" CausesValidation=False
OnCommand="CopyLinkButton_Command" CommandName='Id'
CommandArgument='<%# Container.DataItem("id") %>' Runat=server>
<%# Container.DataItem("id") %>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
what I have below sort of works,
Class myLinkButtonColumn
Implements ITemplate
Sub instantiatein(ByVal container As Control) Implements
ITemplate.InstantiateIn
Dim btn As New LinkButton
btn.ID = "lnkData"
btn.CausesValidation = False
btn.CommandName = "id"
AddHandler btn.DataBinding, AddressOf Me.BindButtonColumn
AddHandler btn.Command, AddressOf Me.LinkButton_Command
container.Controls.Add(btn)
End Sub
Sub BindButtonColumn(ByVal sender As Object, ByVal e As EventArgs)
Dim btn As LinkButton = CType(sender, LinkButton)
Dim container As DataGridItem = CType(btn.NamingContainer,
DataGridItem)
btn.Text =
Convert.ToString(DataBinder.Eval((CType(container,
DataGridItem)).DataItem, "id"))
btn.CommandArgument =
Convert.ToString(DataBinder.Eval((CType(container,
DataGridItem)).DataItem, "id"))
End Sub
Sub LinkButton_Command(ByVal sender As Object, ByVal e As
CommandEventArgs)
MsgBox("hello world")
End Sub
End Class
the id values are showing up and they are clickable, but the problem is
when a value is clicked, the LinkButton_Command does not get called and
the datagrid disappears to boot!
Any help will be appreciated.
Regards,
Burak
I am trying to write the dynamic code behind version of this code in
the data behind:
<asp:TemplateColumn HeaderStyle-ForeColor="white" Headertext="ID">
<ItemTemplate>
<asp:LinkButton ID="lnkCopyPnl" CausesValidation=False
OnCommand="CopyLinkButton_Command" CommandName='Id'
CommandArgument='<%# Container.DataItem("id") %>' Runat=server>
<%# Container.DataItem("id") %>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateColumn>
what I have below sort of works,
Class myLinkButtonColumn
Implements ITemplate
Sub instantiatein(ByVal container As Control) Implements
ITemplate.InstantiateIn
Dim btn As New LinkButton
btn.ID = "lnkData"
btn.CausesValidation = False
btn.CommandName = "id"
AddHandler btn.DataBinding, AddressOf Me.BindButtonColumn
AddHandler btn.Command, AddressOf Me.LinkButton_Command
container.Controls.Add(btn)
End Sub
Sub BindButtonColumn(ByVal sender As Object, ByVal e As EventArgs)
Dim btn As LinkButton = CType(sender, LinkButton)
Dim container As DataGridItem = CType(btn.NamingContainer,
DataGridItem)
btn.Text =
Convert.ToString(DataBinder.Eval((CType(container,
DataGridItem)).DataItem, "id"))
btn.CommandArgument =
Convert.ToString(DataBinder.Eval((CType(container,
DataGridItem)).DataItem, "id"))
End Sub
Sub LinkButton_Command(ByVal sender As Object, ByVal e As
CommandEventArgs)
MsgBox("hello world")
End Sub
End Class
the id values are showing up and they are clickable, but the problem is
when a value is clicked, the LinkButton_Command does not get called and
the datagrid disappears to boot!
Any help will be appreciated.
Regards,
Burak