I am using a FormTemplate for insert/update of items in a grid.
And
I want to default these fields after the first items is added to the grid to the values entered during the first insert.
To capture the values I have added this in the ItemInserted method:
This does capture the values perfectly.
I then added this to the ItemCreated method:
This does work and sets intended value, however, after that the bind ( ie Bind( "EnteredBy" ) ) on the control fires and the intended values are discarded.
The bind has to be there for edits, and the initial insert fails if they are not there complaining of null values, so how can I only bind on initial insert and edit?
<telerik:RadComboBox ID="Location" Style="float: left; font-weight: bold;" skin="WebBlue" SelectedValue='<%# Bind( "Location" ) %>' runat="server" > |
<Items> |
<telerik:RadComboBoxItem Text="Fuquay" Value="Fuquay" /> |
<telerik:RadComboBoxItem Text="Ogden" Value="Ogden" /> |
</Items> |
</telerik:RadComboBox> |
<telerik:RadTextBox ID="EnteredBy" skin="WebBlue" MaxLength="50" Text='<%# Bind( "EnteredBy" ) %>' runat="server" /> |
I want to default these fields after the first items is added to the grid to the values entered during the first insert.
To capture the values I have added this in the ItemInserted method:
if (Session["EnteredBy"] == null) |
{ |
RadTextBox EnteredBy = (RadTextBox)e.Item.FindControl("EnteredBy"); |
if (EnteredBy != null) |
{ |
Session["EnteredBy"] = EnteredBy.Text; |
} |
} |
if (Session["Location"] == null) |
{ |
RadComboBox Location = (RadComboBox)e.Item.FindControl("Location"); |
if (Location != null) |
{ |
Session["Location"] = Location.SelectedValue; |
} |
} |
This does capture the values perfectly.
I then added this to the ItemCreated method:
if (e.Item is GridEditFormItem) |
{ |
RadTextBox EnteredBy = (RadTextBox)e.Item.FindControl("EnteredBy"); |
if (EnteredBy != null) |
{ |
if (Session["EnteredBy"] != null) |
{ |
EnteredBy.Text = Session["EnteredBy"].ToString(); |
} |
} |
RadComboBox Location = (RadComboBox)e.Item.FindControl("Location"); |
if (Location != null) |
{ |
if (Session["Location"] != null) |
{ |
Location.SelectedValue = Session["Location"].ToString(); |
} |
else |
{ |
Location.SelectedValue = "Fuquay"; |
} |
} |
} |
This does work and sets intended value, however, after that the bind ( ie Bind( "EnteredBy" ) ) on the control fires and the intended values are discarded.
The bind has to be there for edits, and the initial insert fails if they are not there complaining of null values, so how can I only bind on initial insert and edit?