14 Answers, 1 is accepted
0
Hello Michael,
I recommend you try the DefaultInsertValue property:
Alternatively you could insert the desired value programatically:
Inserting values in-place and EditForms
Inserting values using UserControl/FormTemplate
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I recommend you try the DefaultInsertValue property:
<
telerik:GridBoundColumn
DataField
=
"Area"
HeaderText
=
"Area"
DefaultInsertValue
=
"24"
/>
Alternatively you could insert the desired value programatically:
Inserting values in-place and EditForms
Inserting values using UserControl/FormTemplate
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Michael
Top achievements
Rank 2
answered on 18 Feb 2010, 05:57 PM
thanks for reply ,
about the Alternatively solution i can't do this, i build my grid programmatically so i can't set the default insert value easy. i will take more time and more code.
please help me to find a solution to make DefaultInsertValue Property works fine.
0
Hello Michael,
I'm not sure that I understand what exactly mean that "it doesn't work" - please elaborate a bit on the problem.
Also I would like to know, which version of RadControls you use in your scenario? Could you provide an example where the DefaultInsertValue property doesn't work??
Thank you for your assistance.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
I'm not sure that I understand what exactly mean that "it doesn't work" - please elaborate a bit on the problem.
Also I would like to know, which version of RadControls you use in your scenario? Could you provide an example where the DefaultInsertValue property doesn't work??
Thank you for your assistance.
Best regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Mike
Top achievements
Rank 1
answered on 24 Nov 2010, 07:03 AM
Using Telerik.Web.UI (Telerik RadControls for ASP.NET Ajax) 2010.3.1109.40, .Net Runtime v4.0.30319.
DefaultInsertValue is a static text while I need to set default insert value of the column to current date. I tried setting DefaultInsertValue to current date in several events of the grid, but it didn't help (value of the column editor remained empty).
I found only one solution:
DefaultInsertValue is a static text while I need to set default insert value of the column to current date. I tried setting DefaultInsertValue to current date in several events of the grid, but it didn't help (value of the column editor remained empty).
I found only one solution:
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e) {
if
(e.Item
is
GridEditFormInsertItem) {
GridDateTimeColumnEditor editor = (e.Item
as
GridEditFormInsertItem).EditManager.GetColumnEditor(
"WORK_DATE"
)
as
GridDateTimeColumnEditor;
editor.Text = DateTime.Today.ToShortDateString();
}
}
0
Hello Mike,
There are two common ways to insert predefined values dynamically (depending on the edit mode):
In-place and Edit forms modes:
Inserting values in-place and EditForms
Web User Control and Edit Form template:
Inserting values using UserControl/FormTemplate
Best regards,
Daniel
the Telerik team
There are two common ways to insert predefined values dynamically (depending on the edit mode):
In-place and Edit forms modes:
Inserting values in-place and EditForms
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled =
true
;
Hashtable values =
new
Hashtable();
values[
"Date"
] = DateTime.Now;
//...
e.Item.OwnerTableView.InsertItem(values);
}
}
Web User Control and Edit Form template:
Inserting values using UserControl/FormTemplate
Best regards,
Daniel
the Telerik team
Browse the vast support resources we have to jumpstart your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Stacy
Top achievements
Rank 1
answered on 17 Jan 2011, 02:12 PM
Hi,
I am using a grid and when a user goes into InsertMode, I have a date control that I want to be able to set a default value for. The user is free to change the date but I want a default value to show when the user first enters the InsertMode. I have seen some questions in the forum but the answers seem to insert a default value in the db without the user knowing. I want the user to be able to see the default value when they are trying to add a new record. Any ideas?
Thanks.
I am using a grid and when a user goes into InsertMode, I have a date control that I want to be able to set a default value for. The user is free to change the date but I want a default value to show when the user first enters the InsertMode. I have seen some questions in the forum but the answers seem to insert a default value in the db without the user knowing. I want the user to be able to see the default value when they are trying to add a new record. Any ideas?
Thanks.
0
Princy
Top achievements
Rank 2
answered on 18 Jan 2011, 06:07 AM
Hello Stacy,
ASPX:
You can try any of the following approach to achieve this.
C#:
Thanks,
Princy.
ASPX:
<
telerik:GridTemplateColumn
>
<
EditItemTemplate
>
<
telerik:RadDatePicker
runat
=
"server"
ID
=
"RadDatePicker1"
DbSelectedDate='<%#Bind("BirthDate") %>'>
</
telerik:RadDatePicker
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
You can try any of the following approach to achieve this.
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.InitInsertCommandName)
{
e.Canceled =
true
;
Hashtable values =
new
Hashtable();
values[
"BirthDate"
] = DateTime.Now;
e.Item.OwnerTableView.InsertItem(values);
}
}
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
//if the grid is in insert mode
{
GridEditFormInsertItem editItem = (GridEditFormInsertItem)e.Item;
RadDatePicker datepicker = (RadDatePicker)editItem.FindControl(
"RadDatePicker1"
);
datepicker.SelectedDate = DateTime.Now;
}
}
Thanks,
Princy.
0
Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 17 Apr 2012, 02:11 PM
I having the same type of issue I have a value that I want to save to the database with our the user knowing on a insert only.
I have tried this:
but then the grid goes into insert mode you can still see the column. I tried making it read only the column will disappear but then the value will not save.
any ideas?
I have tried this:
<
telerik:GridBoundColumn
UniqueName
=
"translation"
DataField
=
"Translation"
DefaultInsertValue
=
"false"
Display
=
"false"
/>
but then the grid goes into insert mode you can still see the column. I tried making it read only the column will disappear but then the value will not save.
any ideas?
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2012, 08:42 AM
Hello Andrew,
If you want to hide the column in insert mode, then you can set ReadOnly as true. From InsertCommand you can insert the value of the particular field by giving a default value. Here is the sample code.
aspx:
C#:
Thanks,
Shinu.
If you want to hide the column in insert mode, then you can set ReadOnly as true. From InsertCommand you can insert the value of the particular field by giving a default value. Here is the sample code.
aspx:
<
telerik:GridBoundColumn
UniqueName
=
"OrderID"
DataField
=
"OrderID"
HeaderText
=
"OrderID"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"EmployeeID"
DataField
=
"EmployeeID"
HeaderText
=
"EmployeeID"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
UniqueName
=
"ShipName"
DataField
=
"ShipName"
HeaderText
=
"ShipName"
ReadOnly
=
"true"
></
telerik:GridBoundColumn
>
C#:
protected
void
radgrid1_InsertCommand(
object
sender, GridCommandEventArgs e)
{
GridEditableItem editItem = (GridEditableItem)e.Item;
string
OrderId = (editItem[
"OrderID"
].Controls[0]
as
TextBox).Text;
string
EmployeeID = (editItem[
"EmployeeID"
].Controls[0]
as
TextBox).Text;
string
ShipName = (editItem[
"ShipName"
].Controls[0]
as
TextBox).Text;
string
insertQuery =
"insert into Orders (OrderID,EmployeeID,ShipName) values ('"
+ OrderId +
"','"
+ EmployeeID +
"','Titanic')"
;
conn.Open();
SqlCommand.CommandText = insertQuery;
SqlCommand.Connection = conn;
SqlCommand.ExecuteNonQuery();
conn.Close();
}
Thanks,
Shinu.
0
Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 18 Apr 2012, 01:11 PM
ya I know I can do it that way but I would like to do it declaratively, you can almost do it just need to be able to hind the column in edit/insert mode
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2012, 01:38 PM
Hi Andrew,
You can use OnInserting server-side events to set values dynamically. Sample code is given below.
ASPX:
C#:
Thanks,
Shinu.
You can use OnInserting server-side events to set values dynamically. Sample code is given below.
ASPX:
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
InsertCommand="INSERT INTO Employees (OrderID,EmployeeID,ShipName) values(@OrderID,@EmployeeID,@ShipName)"
OnInserting="SqlDataSource1_Inserting">
<
InsertParameters
>
<
asp:Parameter
Name
=
"OrderID"
/>
<
asp:Parameter
Name
=
"EmployeeID"
/>
<
asp:Parameter
Name
=
"ShipName"
/>
</
InsertParameters
>
</
asp:SqlDataSource
>
C#:
protected
void
SqlDataSource1_Inserting(
object
sender, SqlDataSourceCommandEventArgs e)
{
e.Command.Parameters[
"@ShipName"
].Value =
"newvalue"
;
}
Thanks,
Shinu.
0
Andrew
Top achievements
Rank 1
Veteran
Iron
answered on 18 Apr 2012, 02:14 PM
again I know that but I do not want to use the code behind I would like to do it declaratively
0
Shinu
Top achievements
Rank 2
answered on 18 Apr 2012, 02:28 PM
Hi Andrew,
Try setting the DefaultValue in the InsertParameters.
ASPX:
Thanks,
Shinu.
Try setting the DefaultValue in the InsertParameters.
ASPX:
<
InsertParameters
>
<
asp:Parameter
Name
=
"ShipName"
Type
=
"String"
DefaultValue
=
"newvalue"
/>
</
InsertParameters
>
Thanks,
Shinu.
0
shervinrv
Top achievements
Rank 1
answered on 01 Aug 2014, 08:01 PM
hi guys .
i know this thread is old .
but it's on top google result
so i post here
to insert default value use EmptyDataText="*****" property .
it will work
i know this thread is old .
but it's on top google result
so i post here
to insert default value use EmptyDataText="*****" property .
it will work