How to get values from template fields in GridView?

前端 未结 5 707
伪装坚强ぢ
伪装坚强ぢ 2021-01-05 06:56

This is my markup of GridView.


    
        
            

        
5条回答
  •  一生所求
    2021-01-05 07:19

    {cell}.Text will only work if there isn't a control within the TemplateField. You have added a label to your template which is why you first need to find the control, cast your object to the control and access the control's properties as needed.

    If you want a more generic approach you could always do the following (remove the label control and simply add the evaluated field):

    
        
            
                <%# DataBinder.Eval(Container.DataItem, "Customer.Name")%>
            
         
         
             
                 <%# DataBinder.Eval(Container.DataItem, "Pickuppoint")%>
             
         
    
    

    When you use the code you initially used, the {cell}.Text should no longer return empty.

提交回复
热议问题