|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Label text from template column is blank in ItemCommand eventlabel controls and an image button. The image button causes the Products_ItemCommand event to fire; however, the value of ItemID is "". Can anyone explain why this is so and how to get around it? Thanks! HTML: <asp:Label id="ItemIDLabel" runat="server" text='<%# Container.DataItem("ItemID")%>'></asp:Label> CODE BEHIND: Private Sub Products_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Products.ItemCommand If (e.CommandName = "AddToCart") Then 'Add to cookie Dim ItemID As Label ItemID = CType(e.Item.Cells(0).FindControl("ItemIDLabel"), Label) Response.Write(ItemID) End If End Sub I figured out the solution within 5 minutes of posting this question :)
I encapsulated the databinding into a method called BindData and then called BindData from inside the ItemCommand method: CODE BEHIND: Private Sub Products_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles Products.ItemCommand If (e.CommandName = "AddToCart") Then BindData() 'Add to cookie Dim ItemID As Label ItemID = CType(e.Item.Cells(0).FindControl("ItemIDLabel"), Label) Response.Write(ItemID) End If End Sub Hi Kim,
Unless the datagrid's viewstate is disabled, you can directly get data from the datagrid without re-binding datagrid's data source. HTH Elton Wang elton_w***@hotmail.com >-----Original Message----- BindData and then>I figured out the solution within 5 minutes of posting this question :) > > >I encapsulated the databinding into a method called >called BindData from inside the ItemCommand method: Object, ByVal e As> >CODE BEHIND: > Private Sub Products_ItemCommand(ByVal sender As Show quoteHide quote > >System.Web.UI.WebControls.DataGridCommandEventArgs) Handles >Products.ItemCommand > If (e.CommandName = "AddToCart") Then > > BindData() > 'Add to cookie > Dim ItemID As Label > ItemID = >CType(e.Item.Cells(0).FindControl("ItemIDLabel"), >Label) > Response.Write(ItemID) > End If > End Sub > >. >
How can I display hashtable key values in a web page?
assigning itemtemplate, edititemtemplate programmatically Move bound column to right of dynamic column in datagrid? Print WebForm DataGrid problem exporting datagrid to excel can i use dynamic variable inside a dataadapter and bind to datagrid How to pull the data out from two table and bind to repeater User Control ASP .Net Message box help Needed Very urgent SortCommand and PageIndexChange event not firing |
|||||||||||||||||||||||