How to perform ondatabinding event?
Suppose there is checkBox with id chkSelect and to perform ondatabinding开发者_如何学JAVA event.How to do that?
You can add AutoPostBack="true"
and OnCheckedChanged="chkSelect_CheckChanged"
to your chkSelect CheckBox, then add this in your codebehind:
protected void chkSelect_CheckChanged(object sender, EventArgs e)
{
// your code here
}
if you want to perform actions when the CheckBox is checked/unchecked.
Or add OnDataBinding="chkSelect_DataBinding"
to your CheckBox and the following in your codebehind:
protected void chkSelect_DataBinding(object sender, EventArgs e)
{
// your code here
}
if you want to use the OnDataBinding event.
I suppose you want to get ondatabinding event method called.
For this your check box should have event declared as:
<asp:CheckBox runat="server" ID="chkSelect" Text="CheckBox to bind" ondatabinding="chkSelect_DataBinding"/>
or
you can also do it Page_init or OnInit method as
protected override void OnInit(EventArgs e)
{
chkSelect.DataBinding += new EventHandler(chkSelect_DataBinding);
base.OnInit(e);
}
Now to let this event fire, you can call
chkSelect.DataBind(); in page_load. This will fire ondatabinding event.
精彩评论