Help Req: !!! :- On Disabling Controls Present inside a Gridview control

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.Crying)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
anoop_jose
11/6/2008 7:16:26 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

3 Replies
1479 Views

Similar Articles

[PageSpeed] 5

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
navsmca
11/6/2008 10:03:19 AM

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
anoop_jose
11/6/2008 2:18:45 PM

Finally i got the results .... Big Smile

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
anoop_jose
11/6/2008 8:00:59 PM
Reply:

Similar Artilces:

Getting the control id of a control inside gridview control
 uhmm.. a little bit confusing regarding my subject because i dont know how to say it...by the way my problem is how can i get the id of a control (e.g. textbox) inside the gridview... and the textbox is in the templatefield... is there any way i can get its id??  hoping i could get a reply as soon as possible... Regards,MhaeyPlease remember to click “Mark as Answer” on the post that helps you.. =) What do you want's to do by getting the id of the Text box? Do you want's to find particular Textbox with certain id ? Kamran ShahidSr. Software Engineer(MCP,MCAD.net,MC...

Data presentation control in another Data presentation control
 Hello,I want to make a menu with datalist or gridview control.Basically,the menu will be like this,Categories     Sub Categories.For example, for COMPUTING category there will be NOTEBOOKS DESKTOPS etc.There will be a image for CATEGORIES and linkbuttons with Subcategories.If I put a datalist inside a datalist and a link button inside the second datalist visually it satisfies my need.However,CommandArguments come from database to linkbutton.Andwhen one of these command buttons is cliked it must go to proper page.I dont know how to wrie an event_handler ,specifically, for...

Need help binding data to GridView control inside a Repeater control
Hi, How do I bind data to a GridView control that is inside a Repeater control?Thanks,Sam Looks like I bind the data to the Repeater control then handle binding individual sets of data to GridViews in the Repeater's OnItemDataBound event. Is this correct? If so, how do I pull the data back into DataTable in the OnItemDataBound event so that I can further process it i.e. slice it up so that I can bind it to multiple GridViews?Thanks,Sam Hi SamU, Yes, you can handle ItemDataBound event of Repeater to generate the data source of inner GridView. The data source (such as DataTable) of ...

ajax control in data presentation controls
can i add ajax controls (MaskedEdit) to presentation controls (dataGrid, dataForm)?? Hi,of course. But keep in mind that those controls are extenders, so you append them to an existing control. Just convert your GridView / DetailsView-fields into templated fields and add the extender you'd like to use to the controls.RegardsMarco Buerckel Don't forget to mark posts that were helpful as answers. Actually, if you looked at the source code for the Masked Edit Extender, you'd see  [TargetControlType(typeof(TextBox))]Meaning, targeting any control type other than textboxes...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

How do I control one control from another control?
I have a page page1.aspx which is within a master page. On page I have a table with two cells. Within each cell I have placed two controls (ascx) that I have developed. Now I'd like to be able to get these two controls to interact. One needs to update the other. One has some search criteria that the other one needs to update its gridview. One needs to make the other visible/not visible at certain times. Out of the box neither control can see each other at all. Is there a good article or someplace I can find some information on how to do this?  AllAboutFocus.com. Information Technolo...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

gridview control in another gridview control
Hi ia have a questioni have a gridview control which contains button in one colum.now my question is i need another gridview to be placed in the  first gidviewso that when i click on the button the second gridview will populate the data.now my question is how to place second gridview in first gridview.or is there any approach like first grid itself acting as parent and child.please help me  Hi sirikalavalapalli:                I think nested gridview will help you. Check this link and it will show you how...

data presentation controls (how to call the individual controls)
Hi please help me.,i have this question., example i create a site with one control, like textbox. when i double click on the white page, the page load event, in the intellisense, the textbox is visible, but when a formview with a textbox inside, in the same page load event, intellisense, the textbox is not available. how can i do the simple intellisense calling where the textbox is just outside a data presentation control like formview. i mean by this intellisense calling is in VB code view., thanks JFRBPH12™  The textbox is within the formview then you can find it like this...

Cannot access a dropdownlist control inside the gridview control
I am using the Gridview control without a DataSource control. When I click on the Edit button, the page posts back and enters the following code: <code>     Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing         Try            Dim row As GridViewRow = GridView1.Rows(e.NewEditIndex)            Dim ddlCustomerID As DropDownList...

help me! WHY CAN THE TOP GRIDVIEW DETECT CONTROLS BUT THE SECOND GRIDVIEW NOT DETECT CONTROLS?!
Hi guys, two gridviews, same page, but one cant define paramters, the other one can.  the one that works is the first example, the one that doesnt work is the second example.  what is the difference? if you could highlight why example two doesnt detect contorls that would be great!!! example one <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" CellPadding="2&qu...

Edit data with GridView Control ? or another control ? help
I use GrivView in ASP.Net 2.0 to show data from DataTable. And i want to edit some fields in some rows. How can I do it? If i touch EDIT button - all columns, which have ReadOnly=false, switch into EDIT mode. But I want, that in first raw I can edit 2,3 column and in second row only 3 column. How can I do it ? ...

Need help in UpdateProgress Control inside ModalPopup Control
 Hi All,        I need to show the progress control inside ModalPopup Control.  Everytime I hit the button, the modalpopup should show the progress while the background code of the button is working.  Modalpopup dialog show disappear when the background executing is done.  For modalpopup control I set the targetcontrolID as the ID of the button.          When I click the button, the modalpopup dialog show up.  But it doesn't trigger the background code of the button.  Do I miss anythi...

Finding LinkButton Control inside of Repeater control!!! Help
I have LinkButtons in which are placed inside of a repeater control. I am trying to be able to retrieve that linkbuttons .text value in a onclick event. Here is my HTML code:---------------------------------------------------------            <asp:repeater id="topics" runat="server">                <itemtemplate>                   <asp:LinkButton id="TopicLink1"  OnClick="_TopicClick"&...

Web resources about - Help Req: !!! :- On Disabling Controls Present inside a Gridview control - asp.net.presentation-controls

Facebook Apologizes For Disabling Apps, Launches New Feedback Metrics, Granular Enforcement, Disabled ...
Facebook today apologized for suddenly disabling certain apps last month, saying that it “over-weighted certain types of user feedback, causing ...

Apple's wireless phone disabling patent - YouTube
Follow me on twitter at http://twitter.com/timcast Facebook - http://bit.ly/timpool In late August an Apple patent was published outlining technology ...

Disabling perceptions
All band movies are the same but different, especially this one, writes Craig Mathieson.

Heartbleed bug prompts disabling of public federal government sites
All federal departments using software vulnerable to the so-called Heartbleed bug have been ordered to immediately disable public websites.

Heartbleed bug prompts disabling of federal government public websites - CTV News
The federal tax agency says it expects to have its online services running again this weekend after blocking public access on April 9 due to ...

Heartbleed Bug Prompts Disabling Of Federal Government Public Websites
OTTAWA - The federal tax agency says it expects to have its online services running again this weekend after blocking public access on April ...

Home Depot confirms plans to accept Apple Pay soon after disabling it
... to find more special coverage of Apps and iOS . What do you think? Discuss "Home Depot confirms plans to accept Apple Pay soon after disabling ...

Retailers disabling NFC payments in preparation for new wireless payment method
Google Wallet never really gained popularity. It was fun paying for things by tapping your phone to a sensor, but not enough people knew about ...

Keychain app, Disabling screenshot sound [From the Forums]
From the Forums Just in case you missed out on some of the Android news today, now is the time to go ahead and get yourself fully caught up. ...

MX Player Updated With Android 5.0 Support, File Viewing Options, Easy Audio Track Disabling, And More ...
MX Player is now ready for Android Lollipop. No, it's not any prettier than it was before. There's no Material Design to drool over, no bright ...

Resources last updated: 1/8/2016 1:14:06 PM