Get the value of a BoundField from a DetailsView

后端 未结 4 499
星月不相逢
星月不相逢 2021-01-20 02:43

I seem to always have problems with this. I have a button outside of the View that calls a function that needs an OrderNumber. I keep getting an error,

4条回答
  •  旧时难觅i
    2021-01-20 02:59

    There is no TextBox control in your details view, you should use a TemplateField, like this:

    
        
            
            
                
                    
                    
               
            
            
            
        
    
    

    Then you can use the FindControl() method to get the Label control by ID value, like this:

    Label theOrderNumberLabel = Order_DetailsView.FindControl("LabelOrderNumber") as Label;
    
    // Verify that we found the label before we try to use it
    if(theOrderNumberLabel != null)
    {
        string orderNumberText = theOrderNumberLabel.Text;
    
        // Do something with order number here
    
    }
    

提交回复
热议问题