Hi All, We have A requirement Where we have disable controls inside a grid.These controls can be textbox, DropDownlist (in TemplateField), ComandField present inside the grid.We have to call a generic method for doing the same .(since it can be done for multiple grid.) PFB the code snippet we use.Which disables all the controls inside the page.
The bolded part of the code is used to loop inside a grid view.(Not Working.)Is this ideal way to deal with the requirement.Or can someone suggest be a better way.
public void DisableMe(Page p1, string strStatus) { if (strStatus != null) { if (strStatus.ToUpper() == "TRUE") { foreach (Control page in p1.Controls) { foreach (Control page1 in page.Controls) { foreach (Control page2 in page1.Controls) { foreach (Control page3 in page2.Controls) { foreach (Control page4 in page3.Controls) { foreach (Control page5 in page4.Controls) { if (page5 is TextBox) ((TextBox)page5).Enabled = false; else if (page5 is CheckBox) ((CheckBox)page5).Enabled = false; else if (page5 is DropDownList) ((DropDownList)page5).Enabled = false; else if (page5 is RadioButton) ((RadioButton)page5).Enabled = false; else if (page5 is RadioButtonList) ((RadioButtonList)page5).Enabled = false; else if (page5 is GridView) { foreach (Control Pgrid in ((GridView)page5).Controls) { if (Pgrid is TextBox) ((TextBox)Pgrid).Enabled = false; else if (Pgrid is CheckBox) ((CheckBox)Pgrid).Enabled = false; else if (Pgrid is DropDownList) ((DropDownList)Pgrid).Enabled = false; else if (Pgrid is RadioButton) ((RadioButton)Pgrid).Enabled = false; else if (Pgrid is RadioButtonList) ((RadioButtonList)Pgrid).Enabled = false; //else if comandfiled then code for disabling it too } } } } } } } } } } }
![]() |
0 |
![]() |
U can use Foreach control c in GridViewRow R1 Enable/Disable
Do it for each row of DataGrid/Gridview
Please Mark as Answer if it solved ur problem.
Naveen Kokcha
MCTS.Net
Web Application Developer
Avinex Soft Private Limited.
![]() |
0 |
![]() |
Hi Naveen,
Its not working fine or am i not implemnting it correctly.
Plese Find below the implementation.
**************************************************************************
else if (page5 is GridView) { foreach (Control Pgrid in ((GridView)page5).Rows) { if (Pgrid is TextBox) ((TextBox)Pgrid).Enabled = false; else if (Pgrid is CheckBox) ((CheckBox)Pgrid).Enabled = false; else if (Pgrid is DropDownList) ((DropDownList)Pgrid).Enabled = false; else if (Pgrid is RadioButton) ((RadioButton)Pgrid).Enabled = false; else if (Pgrid is RadioButtonList) ((RadioButtonList)Pgrid).Enabled = false; //else if comandfiled then code for disabling it too } }*****************************************************************************
Advance Thanks,
Anoop Jose
![]() |
0 |
![]() |
Finally i got the results ....
Thanks Naveen for you valuble Help .....
PFB the Code snippet ....
********************************************************************************************************************
else if (p5 is GridView) { //sMessage = sMessage + "\n\n" + "p5 Grid :- " + ((GridView)p5).ID.ToString(); foreach (Control PGRow in ((GridView)p5).Rows) { foreach (Control cell in PGRow.Controls) { foreach (Control Pgrid in cell.Controls) { //sMessage = sMessage + "\n\n" + "Pgrid ######### " + Pgrid.ToString(); if (Pgrid is TextBox) { ((TextBox)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID" + ((TextBox)Pgrid).ID.ToString(); } else if (Pgrid is CheckBox) { ((CheckBox)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID" + ((CheckBox)Pgrid).ID.ToString(); } else if (Pgrid is DropDownList) { ((DropDownList)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID" + ((DropDownList)Pgrid).ID.ToString(); } else if (Pgrid is RadioButton) { ((RadioButton)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID" + ((RadioButton)Pgrid).ID.ToString(); } else if (Pgrid is RadioButtonList) { ((RadioButtonList)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID" + ((RadioButton)Pgrid).ID.ToString(); } else if (Pgrid is Button) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID Button :- " + ((Button)Pgrid).ID.ToString(); ((Button)Pgrid).Enabled = false; } else if (Pgrid is ImageButton) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID ImageButton :- " + ((ImageButton)Pgrid).ID.ToString(); ((ImageButton)Pgrid).Enabled = false; } else if (Pgrid is CommandField) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN GRID ImageButton :- " + Pgrid.ID.ToString(); Pgrid.Visible = false; } } } } if (((GridView)p5).FooterRow != null) { foreach (Control cell in ((GridView)p5).FooterRow.Cells) { foreach (Control Pgrid in cell.Controls) { //sMessage = sMessage + "\n\n" + "Pgrid ######### " + Pgrid.ToString(); if (Pgrid is TextBox) { ((TextBox)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID" + ((TextBox)Pgrid).ID.ToString(); } else if (Pgrid is CheckBox) { ((CheckBox)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID" + ((CheckBox)Pgrid).ID.ToString(); } else if (Pgrid is DropDownList) { ((DropDownList)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID" + ((DropDownList)Pgrid).ID.ToString(); } else if (Pgrid is RadioButton) { ((RadioButton)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID" + ((RadioButton)Pgrid).ID.ToString(); } else if (Pgrid is RadioButtonList) { ((RadioButtonList)Pgrid).Enabled = false; //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID" + ((RadioButton)Pgrid).ID.ToString(); } else if (Pgrid is Button) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID Button :- " + ((Button)Pgrid).ID.ToString(); ((Button)Pgrid).Enabled = false; } else if (Pgrid is ImageButton) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID ImageButton :- " + ((ImageButton)Pgrid).ID.ToString(); ((ImageButton)Pgrid).Enabled = false; } else if (Pgrid is CommandField) { //sMessage = sMessage + "\n\n" + "Pgrid ***IN FOOTER GRID ImageButton :- " + Pgrid.ID.ToString(); Pgrid.Visible = false; } } } } }********************************************************************************************************************
Thanks ,
Anoop Jose
![]() |
0 |
![]() |