How to link code for button function to checkboxlist in C#?

76 views Asked by At

I would like to link the function of my Chart Output Button to the items in my check box list such that when an item in the check box is selected or deselected, the page is reloaded again and my chart is refreshed.

My codes to refresh the chart have already been included for the Chart Output Button.

 protected void ChartOutputButton_Click(object sender, EventArgs e)
    { //do something }

protected void CheckBoxList1_SelectedIndexhanged(object sender, EventArgs e)
{ // display ChartOutputButton method here }

Thanks.

2

There are 2 answers

0
Shaharyar On BEST ANSWER

You can directly call button event handler which generates the chart:

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);
}
3
SteveFerg On

Is this what you mean?

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(); 
}