Disable the “Add New” button in Rad Grid
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:
asp.net vb.net radgrid
add a comment |
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:
asp.net vb.net radgrid
add a comment |
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:
asp.net vb.net radgrid
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:
asp.net vb.net radgrid
asp.net vb.net radgrid
edited Nov 18 '18 at 9:03
Prashant Pimpale
3,3323830
3,3323830
asked Nov 18 '18 at 6:41
aaaaaa
86
86
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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
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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Nov 23 '18 at 11:16
ajakblackgoatajakblackgoat
1,744197
1,744197
add a comment |
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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