Get the value of a BoundField from a DetailsView

后端 未结 4 495
星月不相逢
星月不相逢 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条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-20 02:52

    There should be a TemplateField as below:

    
    
        
        
        
                        
            
                
                                
        
    
    
    

    Then you could access it this way:

    string sOrderNumber = ((TextBox)Order_DetailsView.Rows[0].Cells[0].FindControl("txtOrderNo")).Text;
    

    And for the BoundField value you can do this way:

    protected void Order_DetailsView_DataBound(object sender, EventArgs e)
    {
        string MyOrderNumber = Order_DetailsView.Rows[0].Cells[0].Text;
    }
    

提交回复
热议问题