Product Bundles
DevCraft
All Telerik .NET tools and Kendo UI JavaScript components in one package. Now enhanced with:
Web
Mobile
Document Management
Desktop
Reporting
Testing & Mocking
CMS
UI/UX Tools
Debugging
Free Tools
Support and Learning
Productivity and Design Tools
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
"server"
AutoGenerateColumns
"false"
OnPreRender
"RadGrid1_PreRender"
OnInsertCommand
"RadGrid1_InsertCommand"
DataSourceID
"SqlDataSource1"
>
MasterTableView
TableLayout
"Fixed"
DataKeyNames
"EmployeeID"
CommandItemDisplay
"Top"
Columns
telerik:GridBoundColumn
UniqueName
DataField
HeaderText
/>
"FirstName"
"First Name"
"LastName"
"Last Name"
</
DetailTables
telerik:GridTableView
"TerritoryID"
Name
"Detail"
"SqlDataSource2"
ParentTableRelation
telerik:GridRelationFields
DetailKeyField
MasterKeyField
public
static
string
connection = WebConfigurationManager.ConnectionStrings[
"NorthwindConnectionString"
].ConnectionString;
SqlConnection conn =
new
SqlConnection(connection);
SqlCommand SqlCommand =
SqlCommand();
Int32 EmpId = 0;
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
foreach
(GridDataItem item
in
RadGrid1.MasterTableView.Items)
if
(Convert.ToInt32(item.GetDataKeyValue(
).ToString()) == EmpId)
item.Expanded =
true
;
}
RadGrid1_InsertCommand(
sender, GridCommandEventArgs e)
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
Int32 Id = Convert.ToInt32((insertItem[
].Controls[0]
as
TextBox).Text);
firstname = (insertItem[
TextBox).Text;
lastname = (insertItem[
SqlCommand(
"Insert into Employees(EmployeeID,FirstName,LastName) values(@EmployeeID,@FirstName,@LastName)"
, conn);
SqlCommand.Parameters.Add(
SqlParameter(
"@EmployeeID"
, Id));
"@FirstName"
, firstname));
"@LastName"
, lastname));
conn.Open();
int
count = SqlCommand.ExecuteNonQuery();
conn.Close();
EmpId = Id;