Disable the “Add New” button in Rad Grid












0















So I have Rad Grid that contains data and I have in above the Add New Button. I want when user has permission to add to make it enable if he doses not have then its disable I search for hours for a solution and all I come is this code:



Dim cmditem As GridCommandItem = CType(gvDefCountry.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
Dim ctrl As System.Web.UI.WebControls.Button = CType(cmditem.FindControl("AddNewRecordButton"), System.Web.UI.WebControls.Button)
ctrl.Enabled = False


But every time I run the code, I'm getting this error:




"Index was outside the bounds of the array"




The view looks like:



enter image description here










share|improve this question





























    0















    So I have Rad Grid that contains data and I have in above the Add New Button. I want when user has permission to add to make it enable if he doses not have then its disable I search for hours for a solution and all I come is this code:



    Dim cmditem As GridCommandItem = CType(gvDefCountry.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
    Dim ctrl As System.Web.UI.WebControls.Button = CType(cmditem.FindControl("AddNewRecordButton"), System.Web.UI.WebControls.Button)
    ctrl.Enabled = False


    But every time I run the code, I'm getting this error:




    "Index was outside the bounds of the array"




    The view looks like:



    enter image description here










    share|improve this question



























      0












      0








      0








      So I have Rad Grid that contains data and I have in above the Add New Button. I want when user has permission to add to make it enable if he doses not have then its disable I search for hours for a solution and all I come is this code:



      Dim cmditem As GridCommandItem = CType(gvDefCountry.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
      Dim ctrl As System.Web.UI.WebControls.Button = CType(cmditem.FindControl("AddNewRecordButton"), System.Web.UI.WebControls.Button)
      ctrl.Enabled = False


      But every time I run the code, I'm getting this error:




      "Index was outside the bounds of the array"




      The view looks like:



      enter image description here










      share|improve this question
















      So I have Rad Grid that contains data and I have in above the Add New Button. I want when user has permission to add to make it enable if he doses not have then its disable I search for hours for a solution and all I come is this code:



      Dim cmditem As GridCommandItem = CType(gvDefCountry.MasterTableView.GetItems(GridItemType.CommandItem)(0), GridCommandItem)
      Dim ctrl As System.Web.UI.WebControls.Button = CType(cmditem.FindControl("AddNewRecordButton"), System.Web.UI.WebControls.Button)
      ctrl.Enabled = False


      But every time I run the code, I'm getting this error:




      "Index was outside the bounds of the array"




      The view looks like:



      enter image description here







      asp.net vb.net radgrid






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 18 '18 at 9:03









      Prashant Pimpale

      3,3323830




      3,3323830










      asked Nov 18 '18 at 6:41









      aaaaaa

      86




      86
























          2 Answers
          2






          active

          oldest

          votes


















          0














          It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.



          However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.






          share|improve this answer































            0














            try this



            If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then

            For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
            Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
            Addbtn.Enabled = False
            Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
            btn.Enabled = False
            Next
            End If





            share|improve this answer


























            • i do not want to hide it i want to just disable it can not click it but its shown

              – aaa
              Nov 19 '18 at 10:30











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358512%2fdisable-the-add-new-button-in-rad-grid%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.



            However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.






            share|improve this answer




























              0














              It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.



              However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.






              share|improve this answer


























                0












                0








                0







                It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.



                However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.






                share|improve this answer













                It should work. Where do you put the codes? if you put it in gvDefCountry_PreRender event of the grid, it will work just fine.



                However, i would recommend you to hide the button altogether instead of disabling it, since there will be no visual difference between enabled and disabled state of the button, depending on the skin you use (In my case - Metro). Otherwise, you also need to change the styles to grey it out and remove the mouse hover effect.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 23 '18 at 11:16









                ajakblackgoatajakblackgoat

                1,744197




                1,744197

























                    0














                    try this



                    If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then

                    For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
                    Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
                    Addbtn.Enabled = False
                    Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
                    btn.Enabled = False
                    Next
                    End If





                    share|improve this answer


























                    • i do not want to hide it i want to just disable it can not click it but its shown

                      – aaa
                      Nov 19 '18 at 10:30
















                    0














                    try this



                    If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then

                    For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
                    Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
                    Addbtn.Enabled = False
                    Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
                    btn.Enabled = False
                    Next
                    End If





                    share|improve this answer


























                    • i do not want to hide it i want to just disable it can not click it but its shown

                      – aaa
                      Nov 19 '18 at 10:30














                    0












                    0








                    0







                    try this



                    If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then

                    For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
                    Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
                    Addbtn.Enabled = False
                    Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
                    btn.Enabled = False
                    Next
                    End If





                    share|improve this answer















                    try this



                    If (TypeOf e.Item Is GridEditableItem) AndAlso (e.Item.IsInEditMode) Then

                    For Each cmdItm As GridCommandItem In RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
                    Dim Addbtn As LinkButton = CType(cmdItm.FindControl("InitInsertButton"), LinkButton)
                    Addbtn.Enabled = False
                    Dim btn As Button = CType(cmdItm.FindControl("AddNewRecordButton"), Button)
                    btn.Enabled = False
                    Next
                    End If






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 28 '18 at 12:31

























                    answered Nov 19 '18 at 8:47









                    Bharath_DeveloperBharath_Developer

                    1797




                    1797













                    • i do not want to hide it i want to just disable it can not click it but its shown

                      – aaa
                      Nov 19 '18 at 10:30



















                    • i do not want to hide it i want to just disable it can not click it but its shown

                      – aaa
                      Nov 19 '18 at 10:30

















                    i do not want to hide it i want to just disable it can not click it but its shown

                    – aaa
                    Nov 19 '18 at 10:30





                    i do not want to hide it i want to just disable it can not click it but its shown

                    – aaa
                    Nov 19 '18 at 10:30


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53358512%2fdisable-the-add-new-button-in-rad-grid%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud

                    Zucchini