Event & Delegets

  • Thread starter Thread starter Islam Elkhayat
  • Start date Start date
I

Islam Elkhayat

I have master datagrid & master details in 5 panels each belong to diffrent
dbtable. I have a dropdpwn list to switch which panel to be visible..

I also have one navigation bar for add, update, delete and i need to the
button to work with the visible panel but the click event don't fire, here
is my code for the dropdownlist selectedindex change:

private void DropDownList1_SelectedIndexChanged(object sender,
System.EventArgs e)
{
switch(DropDownList1.SelectedIndex)
{
case 0 :
ResetPanelVisiblity();
Panel1_PersonalInfo.Visible = true;
this.bt_new.Click += new EventHandler(this.Panel1_NewRecord);
this.bt_edit.Click += new EventHandler(this.Panel1_UpdateRecord);
this.bt_delete.Click += new EventHandler(this.Panel1_Delete);
break;

case 1:
ResetPanelVisiblity();
Panel2_Photo.Visible = true;
this.bt_new.Click += new EventHandler(this.Panel2_NewRecord);
this.bt_edit.Click += new EventHandler(this.Panel2_UpdateRecord);
this.bt_delete.Click += new EventHandler(this.Panel2_Delete);
break;
------------------------------------------------
if i implement a switch case(or if statment) for each button to call methods
it' work.
So How can i fix this problem without use switch case for each button click
event??
regards
 
Can you use a single set of event handlers for all grids? In the event
handler you could check the selected index of the dropdown list and
take the appropriate action. If you do this, you won't need to switch
event handlers for the buttons.

Now you're only left with making the correct panel visible in your
DropDownList1_SelectedIndexChanged event handler. You can make this
generic by using something like

System.Web.UI.WebControls.Panel
objPanel=this.FindControl("Panel"+Convert.ToString(DropDownList1.SelectedIndex+1));
objPanel.Visible=true;

to locate the panel that goes with the selected index. Change the
names of the panels so they are Panel1, Panel2, Panel3, etc.

I hope this helps.

Bill E.
Hollywood, FL
 
Thanx for ur solution..
but doing so mean i will switch in each button handler for the dropdown
selected index... right??
which mean there will be 8 switch case for 8 buttons..
while this is related to the visible panel which is selected by the
dropdownlist so i want to handle all the switching prossess in the
DropDownList selectedIndex change..

can i work around to solve this prblem??
 
I'm not sure why there must be a switch in the event handlers for the
panels. Are you doing INSERTS, UPDATES and DELETES in these handlers?
Are the operations basically the same for each panel, but perhaps a
different stored procedure is called? If so, you can store the
different procedures in an array and reference the index of the array
using DropDownList1.SelectedIndex.

On the other hand, If the operations are very different for each panel,
it becomes more likely that you'll need a switch somewhere in those
event handlers.

Bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top