Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Reference to a controls bound dataset
Message
De
05/08/2003 12:42:06
 
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires Web
Divers
Thread ID:
00816693
Message ID:
00816946
Vues:
24
John,

I'm not sure if natively it can. We set up properties in our control sub-classes and then tell the control what it's bound to in a DataBind method. Also, you need a DataBindingHandler event. Kinda like this:
// These are methods/event handlers in the control 
// (TextBox in this example, although it doesn't matter)
public void DataBind(DataTable dt, string column, int row)
{
  this.m_BoundTable = dt;
  this.m_BoundColumn = column;
  this.m_BoundRow = row;
}

public void DataPostBack()
{
  if (this.m_BoundTable != null && this.m_BoundTable.Rows.Count > this.m_BoundRow)
    if (this.m_BoundTable.Rows[this._BoundRow][this.m_BoundColumn].ToString() != this.Text)
      this.m_BoundTable.Rows[this._BoundRow][this.m_BoundColumn] = this.Text;
}

protected virtual void DataBindingHandler(object sender, System.EventArgs e)
{
  if (this.m_BoundTable != null && this.m_BoundTable.Rows.Count > this.m_BoundRow)
    this.Text = this.m_BoundTable.Rows[this.m_BoundRow][this.m_BoundColumn].ToString();
}
You use it like this:
Call the control's DataBind method for every control on your page, in the Page_Init() method, then call the Page's DataBind:
this.txtMyTextBox.DataBind(MyDataTable, "MyColumn", 0);
this.txtAgain.DataBind(Blah, "Blah", 0);

Page.DataBind();
The call to the Page's DataBind will cause the DataBindingHandler event handler to fire, which will fill your control's .Text so that it will display on your page.

In the Page_Load() method, call the DataPostBack() method. That should do the trick. Oh, also, get your data from a Session variable or something in the Page_Init() prior to doing the DataBind stuff, and put your data back out to the Session variable after calling the DataPostBack() method.

HTH,
~~Bonnie

>How does a control get a reference to the dataset to which it is bound?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform