我用程序生成的控件,如何添加和處理事件?請高手支招

etzrp 2006-07-01 09:19:40
例如
CheckBox cbxFoo=new CheckBox();
cbxFoo.text="why";
someContainer.Controls.add(cbxFoo);
那麽我將如何使用cbxFoo的事件呢?
...全文
254 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
etzrp 2006-07-01
  • 打赏
  • 举报
回复
着急,修改不了魔板列
etzrp 2006-07-01
  • 打赏
  • 举报
回复
yumanqing?請問時間申明一般在什麽地方?都可以嗎!
etzrp 2006-07-01
  • 打赏
  • 举报
回复
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++;
}
}
yumanqing 2006-07-01
  • 打赏
  • 举报
回复
//事件声明
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" )
//{

//}
}
etzrp 2006-07-01
  • 打赏
  • 举报
回复
謝謝,馬上去試一下
flyzq 2006-07-01
  • 打赏
  • 举报
回复
楼上正解
sandsboy 2006-07-01
  • 打赏
  • 举报
回复
cbxFoo.Click+=new EventHandle(yourfunction);

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧