我用程序生成的控件,如何添加和處理事件?請高手支招
例如
CheckBox cbxFoo=new CheckBox();
cbxFoo.text="why";
someContainer.Controls.add(cbxFoo);
那麽我將如何使用cbxFoo的事件呢?
问题点数:20、回复次数:7Top
1 楼sandsboy(竹子)回复于 2006-07-01 09:39:17 得分 0
cbxFoo.Click+=new EventHandle(yourfunction);Top
2 楼flyzq()回复于 2006-07-01 10:00:32 得分 0
楼上正解Top
3 楼ETZRP(www.e-sum.net詹然平)回复于 2006-07-01 10:14:03 得分 0
謝謝,馬上去試一下Top
4 楼yumanqing(笨鸟)回复于 2006-07-01 10:22:26 得分 0
//事件声明
dtProduct.RowChanging+=new DataRowChangeEventHandler(this.Product_RowChanging);
dtProduct.ColumnChanging +=new DataColumnChangeEventHandler(this.Product_ColumnChanging);
}
//自定义的事件处理方法
private void Product_RowChanging(object sender, System.Data.DataRowChangeEventArgs e)
{
if (e.Row.RowState == DataRowState.Deleted)
{
MessageBox.Show("触发删除事件");
return;
}
if (e.Row["Name"].ToString() == "")
{
e.Row.SetColumnError("Name", "不能为空");
}
//if(double.Parse(e.Row["Price"].ToString()))< "0" )
//{
//}
}Top
5 楼ETZRP(www.e-sum.net詹然平)回复于 2006-07-01 10:33:26 得分 0
asp:DataList ID="dtlDisplay" runat="server" DataSourceID="sdsLeagueList" OnItemCreated="dtlDisplay_ItemCreated"
Width="100%" OnLoad="dtlDisplay_Load">
<HeaderTemplate>
<asp:Table ID="tabTitle" runat="server">
<asp:TableRow runat="server">
<asp:TableCell runat="server">
<asp:CheckBox ID="cbxColumnMoneyDate" runat="server" Text="帳日" OnCheckedChanged="cbxColumnMoneyDate_CheckedChanged"
AutoPostBack="True" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="cbxColumnDateTime" runat="server" Text="時間" AutoPostBack="True"
OnCheckedChanged="cbxColumnDateTime_CheckedChanged" />
</asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="cbxColumnTeam" runat="server" Text="隊伍" AutoPostBack="True" OnCheckedChanged="cbxColumnTeam_CheckedChanged" />
</asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox4" runat="server" Text="4" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox5" runat="server" Text="5" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox6" runat="server" Text="6" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox7" runat="server" Text="7" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox8" runat="server" Text="8" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox9" runat="server" Text="9" /></asp:TableCell>
<asp:TableCell runat="server">
<asp:CheckBox ID="CheckBox10" runat="server" Text="10" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</HeaderTemplate>
<asp:Datalist>
我要訪問header,但是老是不能修改,不知道怎麽囘事情?
Table tab = (Table)dtlDisplay.Controls[0].FindControl("tabTitle");
IPost = odsSportPost.Select();
int i = GRIDVIEW_START_INDEX;
foreach (DataRowView Post in IPost)
{
if (Convert.ToBoolean(Post["m_status"]) == false)
{
if (i >= GRIDVIEW_END_INDEX)
break;
CheckBox cbx = new CheckBox();
cbx.Text = cstr(Post["m_post_class_name"]);
((Table)dtlDisplay.Controls[0].FindControl("tabTitle")).Rows[0].Cells[i].Controls.Add(cbx);
i++;
}
}Top
6 楼ETZRP(www.e-sum.net詹然平)回复于 2006-07-01 10:34:21 得分 0
yumanqing?請問時間申明一般在什麽地方?都可以嗎!Top
7 楼ETZRP(www.e-sum.net詹然平)回复于 2006-07-01 10:49:27 得分 0
着急,修改不了魔板列Top




