如何将按钮函数的代码链接到C#中的复选框列表?
我希望将“我的图表输出”按钮的功能链接到“我的复选框”列表中的项目,以便在选中或取消选中复选框中的项目时,再次重新加载页面并刷新我的图表 “图表输出”按钮中已包含刷新图表的代码如何将按钮函数的代码链接到C#中的复选框列表?,c#,button,methods,checkboxlist,asp.net-4.5,C#,Button,Methods,Checkboxlist,Asp.net 4.5,我希望将“我的图表输出”按钮的功能链接到“我的复选框”列表中的项目,以便在选中或取消选中复选框中的项目时,再次重新加载页面并刷新我的图表 “图表输出”按钮中已包含刷新图表的代码 protected void ChartOutputButton_Click(object sender, EventArgs e) { //do something } protected void CheckBoxList1_SelectedIndexhanged(object sender, Event
protected void ChartOutputButton_Click(object sender, EventArgs e)
{ //do something }
protected void CheckBoxList1_SelectedIndexhanged(object sender, EventArgs e)
{ // display ChartOutputButton method here }
谢谢。这就是你的意思吗
protected void ChartOutputButton_Click(object sender, EventArgs e)
{
chart_refresh();
}
private void chart_refresh()
{
// do somethiing
}
protected void CheckBoxList1_SelectedIndexhanged(object sender, EventArgs e)
{
// display ChartOutputButton method here
chart_refresh();
}
您可以直接调用生成图表的按钮事件处理程序:
protected void ChartOutputButton_Click(object sender, EventArgs e)
{
//your code to generate chart
}
protected void CheckBoxList1_SelectedIndexhanged(object sender, EventArgs e)
{
//you can call ChartOutputButton click event handler here
ChartOutputButton_Click(ChartOutputButton, null);
}
是的,这就是我一直在寻找的。只是想知道,有没有其他方法可以将按钮链接到复选框列表而不创建chart\u refresh()方法?您可以这样做:ChartOutputButton\u单击((对象)ChartOutputButton,null);注意:为了保持一致,将按钮强制转换为(对象)。这假设您不关心EventArgs,也不需要将按钮强制转换为对象,它已经被对象继承了