Hello,
I was wondering whether I am able to do batch input with auto-generated columns?
This is my grid declaration.
Whenever I click new row, a row appears but it is empty - no textboxes or anything. Am I missing something?
Regards, Paul.
I was wondering whether I am able to do batch input with auto-generated columns?
This is my grid declaration.
<
telerik:RadGrid
ID
=
"rgTimeDetails"
runat
=
"server"
OnNeedDataSource
=
"rgTimeDetails_NeedDataSource"
OnColumnCreated
=
"rgTimeDetails_ColumnCreated"
CellSpacing
=
"0"
GridLines
=
"None"
>
<
MasterTableView
EditMode
=
"Batch"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"timeid,staffid"
>
<
BatchEditingSettings
OpenEditingEvent
=
"DblClick"
EditType
=
"Row"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
Whenever I click new row, a row appears but it is empty - no textboxes or anything. Am I missing something?
Regards, Paul.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 18 Oct 2013, 05:08 AM
Hi Paul,
Please try the sample code snippet for Batch Edit,it works fine at my end.
ASPX:
C#:
Thanks,
Princy
Please try the sample code snippet for Batch Edit,it works fine at my end.
ASPX:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"true"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnBatchEditCommand
=
"RadGrid1_BatchEditCommand"
>
<
MasterTableView
EditMode
=
"Batch"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"OrderID"
>
<
BatchEditingSettings
OpenEditingEvent
=
"DblClick"
EditType
=
"Row"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
<
br
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
""
></
asp:Label
>
C#:
public
static
string
connection = WebConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(connection);
DataTable dt1 =
new
DataTable();
protected
void
RadGrid1_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
string
selectQuery1 =
"SELECT [OrderID], [ShipName] FROM [Orders]"
;
SqlDataAdapter adapter1 =
new
SqlDataAdapter(selectQuery1, conn);
conn.Open();
adapter1.Fill(dt1);
conn.Close();
RadGrid1.DataSource = dt1;
}
protected
void
RadGrid1_BatchEditCommand(
object
sender, GridBatchEditingEventArgs e)
{
foreach
(GridBatchEditingCommand command
in
e.Commands)
{
Hashtable newValues = command.NewValues;
Hashtable oldValues = command.OldValues;
string
OrderID = newValues[
"OrderID"
].ToString();
string
ShipName = newValues[
"ShipName"
].ToString();
try
{
conn.Open();
string
query =
"UPDATE Orders SET ShipName='"
+ ShipName +
"' WHERE OrderID = '"
+ OrderID +
"'"
;
SqlCommand cmd =
new
SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
Label1.Text =
"Product with ID "
+ OrderID +
" is updated!"
;
}
catch
(Exception ex)
{
Label1.Text =
"Product with ID "
+ OrderID +
" cannot be updated. "
;
}
}
}
Thanks,
Princy
0
Paul
Top achievements
Rank 1
answered on 18 Oct 2013, 08:12 AM
Thanks for the response Princy. I have compared mine with yours and its virtually the same but mine isn't working.
Not sure if it matters but my RadGrid is inside a RadWindow?
I have attached a screenshot to show what is happening. If I double click on a row, nothing happens.
Regards, Paul.
Not sure if it matters but my RadGrid is inside a RadWindow?
I have attached a screenshot to show what is happening. If I double click on a row, nothing happens.
Regards, Paul.
0
Princy
Top achievements
Rank 2
answered on 21 Oct 2013, 08:00 AM
Hi Paul,
Its hard to identify the issue,the code works fine at my end.Here is the code I tried using a window.If this doesn't help,please provide your full code snippet.
ASPX:
C#:
Thanks,
Princy
Its hard to identify the issue,the code works fine at my end.Here is the code I tried using a window.If this doesn't help,please provide your full code snippet.
ASPX:
<
telerik:RadWindowManager
ID
=
"RadWindowManager1"
runat
=
"server"
EnableShadow
=
"true"
>
<
Windows
>
<
telerik:RadWindow
ID
=
"UserListDialog"
runat
=
"server"
Title
=
"Editing record"
Height
=
"320px"
Width
=
"310px"
Left
=
"150px"
ReloadOnShow
=
"true"
ShowContentDuringLoad
=
"false"
Modal
=
"true"
>
<
ContentTemplate
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
AllowPaging
=
"true"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
OnBatchEditCommand
=
"RadGrid1_BatchEditCommand"
>
<
MasterTableView
EditMode
=
"Batch"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"OrderID"
>
<
BatchEditingSettings
OpenEditingEvent
=
"DblClick"
EditType
=
"Row"
/>
</
MasterTableView
>
</
telerik:RadGrid
>
<
br
/>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
Text
=
""
></
asp:Label
>
</
ContentTemplate
>
</
telerik:RadWindow
>
</
Windows
>
</
telerik:RadWindowManager
>
<
telerik:RadButton
ID
=
"rbShowDialog"
Text
=
"Show the Window"
runat
=
"server"
/>
C#:
public
static
string
connection = WebConfigurationManager.ConnectionStrings[
"Northwind_newConnectionString3"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(connection);
DataTable dt1 =
new
DataTable();
protected
void
Page_Load(
object
sender, EventArgs e)
{
UserListDialog.OpenerElementID = rbShowDialog.ClientID;
}
protected
void
RadGrid1_NeedDataSource(
object
sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
string
selectQuery1 =
"SELECT [OrderID], [ShipName] FROM [Orders]"
;
SqlDataAdapter adapter1 =
new
SqlDataAdapter(selectQuery1, conn);
conn.Open();
adapter1.Fill(dt1);
conn.Close();
RadGrid1.DataSource = dt1;
}
protected
void
RadGrid1_BatchEditCommand(
object
sender, GridBatchEditingEventArgs e)
{
foreach
(GridBatchEditingCommand command
in
e.Commands)
{
Hashtable newValues = command.NewValues;
Hashtable oldValues = command.OldValues;
string
OrderID = newValues[
"OrderID"
].ToString();
string
ShipName = newValues[
"ShipName"
].ToString();
try
{
conn.Open();
string
query =
"UPDATE Orders SET ShipName='"
+ ShipName +
"' WHERE OrderID = '"
+ OrderID +
"'"
;
SqlCommand cmd =
new
SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
Label1.Text =
"Product with ID "
+ OrderID +
" is updated!"
;
}
catch
(Exception ex)
{
Label1.Text =
"Product with ID "
+ OrderID +
" cannot be updated. "
;
}
}
}
Thanks,
Princy