Just need one column of RadGrid to add, and update record to sql table which has only one column with type of integer. I need it to use form templates.
Why this is so difficult.
10 Answers, 1 is accepted
Try using a GridCheckBox column which will render a checkbox in the edit mode.
He is referring to a checkbox he is trying to place in the FormTemplate tag.
I am having the same trouble.
The GridCheckBoxColumn works greate to render a checkbox inside the grid, but when you clic "Add new record" an error is thrown, indicating that the value null is not a valid value for the checkbox "checked" property.
I have tried Bind, Eval, and it won't work.
Here is my code:
|<asp:CheckBox ID="Activada" runat="server" Checked='<%# Bind("Activada") %>' />|
I hope you can help us, I haven't seen a solution to this in any post, or any examples from you, and it is a very basic and common situation.
Thanks in advance.
When the control is in edit mode, the value for the column in question is null, since no value exists yet. Hence, the issue with the binding expression. One possible approach would be to remove the Binding expression, and set the checked/unchecked status from the code-behind. Alternatively, you can conditianally determine if the item is a GridEditFormInsertItem (i.e. the grid is in insert mode):
'<%# (Container is GridEditFormInsertItem) ? "TrueStatement" : "FalseStatement" %>'
I hope this information helps.
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I'm not sure if this would solve your problems but I found a forum link which explains a similar kind of scenario.
Checkbox in FormTemplate- "Specified Cast is Invalid"
Hope this helps atleast to some extent.
I've been hunting down the answer to this one for awhile. I ended up dropping it awhile ago and not doing an in grid edit. I've come back around now in another project and would really like to be able to use a checkbox in a <formtemplate> in a <RadGrid>. Does ANYONE know of a known working solution to this? I've tried all of the above suggestions and even participated in the thread that is listed above. Is there an example in the code examples that Telerik supplies? I can't seem to find it and this is a fairly important thing to not be able to do.
2asp:CheckBox ID="CheckBox11" runat="server" Checked='<%# IIf(Eval("PublichArticle") Is DBNull.Value, "False", Eval("PublichArticle")) %>' />
<asp:CheckBox ID="chkOnaylandi" runat="server" Checked='<%# Bind("Onaylandi") %>' />
in form template and
Private Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
If e.CommandName = RadGrid.InitInsertCommandName Then
e.Canceled = True
Dim newValues As New System.Collections.Specialized.ListDictionary()
newValues("Onaylandi") = 0
in the code side. and I bont deal with dbnull values... Onaylandi field id integer in sqlserver
Here's the C# code I used:
protected void rgUserRequest_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
if (e.CommandName == RadGrid.InitInsertCommandName)
e.Canceled = true;
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["Purchased"] = false;
I also had to add the following to my grid control: OnItemCommand="rgUserRequest_ItemCommand"