Friday, January 7, 2011

GridView rowupdating event not getting new values from controls

I have a code in rowupdating event which get's values from textbox controls during edit mode. However, when update command button is clicked, the values from the controls were cleared or null. So, I checked the page load event, and found out that I have a code which rebinds the grid when it is not post back since the update link button will trigger postback.
Here is the page load code:
Code:
if(!string.IsNullOrEmpty(Request.QueryString["LoanNum"]))  
 {  
  ShowToControls(Convert.ToInt32(Request.QueryString["LoanNum"]));  
  BindGridDetails(Convert.ToInt32(Request.QueryString["LoanNum"]));  
 }  
So, the modified pageload code should add a IsPostback condition so that the binding of gridview will not be executed.
Here's the modified script:
Code:
if(!string.IsNullOrEmpty(Request.QueryString["LoanNum"])  
  && !Page.IsPostBack)  
 {  
  ShowToControls(Convert.ToInt32(Request.QueryString["LoanNum"]));  
  BindGridDetails(Convert.ToInt32(Request.QueryString["LoanNum"]));  
 }  

0 comments:

Post a Comment