This is a migrated thread and some comments may be shown as answers.

Inserting with EditTemplate

4 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 05 Mar 2012, 09:57 PM
Well, I have an EditTemplate that I bound some data to some RadControl. The problem is when I try to insert, I got errors on bound item because they are DBnull. So how can I have the template with empty control while inserting?

Jocelyn

4 Answers, 1 is accepted

Sort by
0
Elliott
Top achievements
Rank 2
answered on 05 Mar 2012, 10:48 PM
for starters, remove any DataType parameters
on numeric text boxes, change the Value= to DBValue=
0
Jocelyn
Top achievements
Rank 1
answered on 06 Mar 2012, 02:40 PM
Thanks Marianne.

I already use DbValue. I got this error on non-rad controls like Checkbox.

What can I do to solve this?
0
Accepted
Princy
Top achievements
Rank 2
answered on 07 Mar 2012, 07:42 AM
Hello Jocelyn,

The reason for this error is that your grid instance can not bind a value for the newly inserted item through the Eval()/Bind() syntax. A solution would be to preset the default value of the control(s) when binding to a grid item on the RadGrid.InitInsertCommandName command.

ASPX:

telerik:GridTemplateColumn HeaderText=""  UniqueName="StartCheckboxColumn" >  
        <ItemTemplate>  
            <asp:CheckBox ID="StartCheckbox" runat="server"  AutoPostBack="true" Checked='<%# Bind("START") %>' />  
        </ItemTemplate>  
    </telerik:GridTemplateColumn>

C#:
protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
{
    if ((e.CommandName == RadGrid.InitInsertCommandName))
          {
        e.Canceled = true;
        //Prepare an IDictionary with the predefined values
        System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
  
        //set initial checked state for the checkbox on init insert
        newValues("START") = false;
  
        //Insert the item and rebind
        e.Item.OwnerTableView.InsertItem(newValues);
    }
}

Hope this helps,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 07 Mar 2012, 04:29 PM
Thanks ! It works!
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Elliott
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or