<edititemtemplate> <mm:mmTextBox id="txtMyValue" runat="server" Text='< %# Bind("myvalue") % >' AutoPostBack="true" MaxLength="9" Width="76px" OnTextChanged="txtMyValue_TextChanged"> </mm:mmTextBox> </edititemtemplate>I'm running into a few problems:
public partial class MyPage : mmBusinessWebPage { protected MyBusiness oMyBusiness; protected DataSet dsMyBusiness; protected void Page_Load(object sender, EventArgs e) { this.oMyBusiness = (MyBusiness)this.RegisterPrimaryBizObj(new MyBusiness()); if (!IsPostBack) { // Load Data this.oMyBusiness.GetData(key); Session["dsMyBusiness"] = this.oMyBusiness.DataSet; } else { // *** this code runs before the TextChanged method *** DataSet dsMyBusiness= (DataSet)Session["dsMyBusiness"]; this.oMyBusiness.SetCurrentDataSet(dsMyBusiness); Session["dsMyBusiness"] = this.oMyBusiness.DataSet; } } }But in the TextChanged method the DataSet set in Page_Load() is Null. Why is that?
/// <summary> /// AJAX postback!!! - Check MyValue and set description /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void txtMyValue_TextChanged(object sender, EventArgs e) { // *** Why is this.dsMyBusiness Null here? **** DataSet ds2 = this.dsMyBusiness; // workaround DataSet ds = (DataSet)Session["dsMyBusiness"]; this.dsMyBusiness.SetCurrentDataSet(ds); // *** is this a mistake? *** // *** why doesn't this hydrate the row.DataItem below? *** // Rebind the GridView this.BindControl(this.gvMyGrid); // mmTextBox tb = (mmTextBox)sender; // if the value exists get the description for the value string myvalue = tb.Text.Replace("-", String.Empty).Trim(); MyForeignTableEntity ftEntity; ftEntity = oMyForeignTable.GetDescription(myvalue); // find the description controls GridViewRow row = this.gridCountSheet.Rows[this.gridCountSheet.EditIndex]; mmLabel lblDescription = (mmLabel)row.Cells[COL_DESCRIPTION].FindControl("lblDescription"); mmTextBox txtDescription = (mmTextBox)row.Cells[COL_DESCRIPTION].FindControl("txtDescription"); // get the row data // *** Why is this Null? *** // Note: The DataItem property is only available during and after the RowDataBound event of a GridView control. // DataRowView drv = row.DataItem as DataRowView; // workaround - use dataset // ??? will EditIndex work when paging is implemented? DataRow dr = ds.Tables[0].Rows[this.gridCountSheet.EditIndex]; // handle updates if (ftEntity == null || ftEntity.Description == null || ftEntity.Description == String.Empty) { // NOT found lblDescription.Visible = false; txtDescription.Visible = true; // put not found value in description text box txtDescription.Text = tb.Text; // clear not found value tb.Text = String.Empty; // store in data row dr["myvalue"] = String.Empty; dr["description"] = tb.Text; } else { // found lblDescription.Visible = true; txtDescription.Visible = false; lblDescription.Text = ftEntity.Description; txtDescription.Text = ftEntity.Description; dr["myvalue"] = myvalue; dr["description"] = ftEntity.Description; } // *** no other values from other controls are saved!!! *** // 1) set entire data row manually from controls? // 2) using wrong data/binding concept here? // 3) set flag here and handle this method's functionality in RowDataBound()? // ******************************************** // Store the DataSet back into the session Session["dsMyBusiness"] = ds; // Rebind the GridView this.BindControl(this.gvMyGrid); }