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"
OnNeedDataSource
"RadGrid1_NeedDataSource"
AllowPaging
"true"
OnUpdateCommand
"RadGrid1_UpdateCommand"
OnInsertCommand
"RadGrid1_InsertCommand"
OnDeleteCommand
"RadGrid1_DeleteCommand"
>
MasterTableView
AutoGenerateColumns
"False"
DataKeyNames
"OrderID"
CommandItemDisplay
"Top"
GroupByExpressions
telerik:GridGroupByExpression
SelectFields
telerik:GridGroupByField
FieldAlias
"ShipName"
FieldName
></
</
GroupByFields
SortOrder
"Descending"
Columns
telerik:GridButtonColumn
CommandName
"Delete"
Text
UniqueName
"DeleteColumn"
ConfirmText
ConfirmDialogType
"RadWindow"
/>
telerik:GridBoundColumn
HeaderText
DataField
ReadOnly
"CustomerID"
telerik:GridEditCommandColumn
"EditCommandColumn"
public
static
DataTable dtTable;
SqlConnection SqlConnection =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"ConnectionString"
].ConnectionString);
SqlDataAdapter SqlDataAdapter =
SqlDataAdapter();
SqlCommand SqlCommand =
SqlCommand();
protected
void
RadGrid1_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
dtTable =
DataTable();
try
SqlConnection.Open();
string
selectQuery =
"SELECT * FROM Orders"
;
SqlDataAdapter.SelectCommand =
SqlCommand(selectQuery, SqlConnection);
SqlDataAdapter.Fill(dtTable);
RadGrid1.DataSource = dtTable;
}
catch
(Exception ex)
RadGrid1.Controls.Add(
LiteralControl(
"Unable to insert Employee. Reason: "
+ ex.Message));
finally
//Close the SqlConnection
SqlConnection.Close();
RadGrid1_InsertCommand(
sender, GridCommandEventArgs e)
GridEditFormInsertItem insertedItem = (GridEditFormInsertItem)e.Item;
CustomerID = (insertedItem[
].Controls[0]
as
TextBox).Text;
ShipName = (insertedItem[
//Open the SqlConnection
//Insert Query to insert into the database
insertQuery =
"INSERT into Orders(CustomerID,ShipName) values('"
+ CustomerID +
"','"
+ ShipName +
"')"
SqlCommand.CommandText = insertQuery;
SqlCommand.Connection = SqlConnection;
SqlCommand.ExecuteNonQuery();
e.Canceled =
true
RadGrid1_DeleteCommand(
//Code to delete
RadGrid1_UpdateCommand(
//Code to Update