or
<
div
>
<
asp:DropDownList
ID
=
"DropDownList1"
runat
=
"server"
AutoPostBack
=
"True"
OnSelectedIndexChanged
=
"DropDownList1_SelectedIndexChanged1"
>
<
asp:ListItem
Value
=
"Table_321"
>Table_321</
asp:ListItem
>
<
asp:ListItem
Value
=
"Table_621"
>Table_621</
asp:ListItem
>
</
asp:DropDownList
>
<
br
/>
<
br
/>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Culture
=
"it-IT"
OnNeedDataSource
=
"RadGrid1_NeedDataSource"
AllowPaging
=
"True"
AllowSorting
=
"True"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
>
<
ExportSettings
ExportOnlyData
=
"True"
>
<
Pdf
PageWidth
=
""
>
</
Pdf
>
</
ExportSettings
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
/>
</
ClientSettings
>
<
MasterTableView
CommandItemDisplay
=
"Top"
>
<
CommandItemSettings
ShowExportToExcelButton
=
"True"
/>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
>
<
HeaderStyle
Width
=
"30px"
/>
</
telerik:GridEditCommandColumn
>
<
telerik:GridButtonColumn
ButtonType
=
"ImageButton"
Text
=
"Delete"
CommandName
=
"Delete"
FilterControlAltText
=
"Filter column1 column"
ConfirmDialogType
=
"RadWindow"
ConfirmText
=
"Do you really want to delete this project and all its content?"
UniqueName
=
"Cancel"
>
<
HeaderStyle
Width
=
"30px"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
UniqueName
=
"EditCommandColumn1"
FilterControlAltText
=
"Filter EditCommandColumn1 column"
></
EditColumn
>
</
EditFormSettings
>
<
PagerStyle
AlwaysVisible
=
"True"
/>
</
MasterTableView
>
<
PagerStyle
AlwaysVisible
=
"True"
/>
</
telerik:RadGrid
>
<
br
/>
<
br
/>
</
div
>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:BOMConnectionString %>">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Id"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"Code"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Bkgroup"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Stgroup"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Quantity"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"BomNote"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"UnitEng"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"AlternCost"
Type
=
"Double"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"Code"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Bkgroup"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Stgroup"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Quantity"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"BomNote"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"UnitEng"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"AlternCost"
Type
=
"Double"
/>
<
asp:Parameter
Name
=
"Id"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
protected void DropDownList1_SelectedIndexChanged1(object sender, EventArgs e)
{
if (DropDownList1.SelectedIndex > -1)
{
RadGrid1.DataSource=null;
RadGrid1.Rebind();
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
string tableInUse = DropDownList1.SelectedItem.Text;
RadGrid1.DataSource = SqlDataSource1;
SqlDataSource1.DeleteCommand = "DELETE FROM [" + tableInUse + "] WHERE [Id] = @Id";
SqlDataSource1.InsertCommand = "INSERT INTO [" + tableInUse + "] ([Code], [Description], [Bkgroup], [Stgroup], [Quantity], [BomNote], [UnitEng], [AlternCost]) VALUES (@Code, @Description, @Bkgroup, @Stgroup, @Quantity, @BomNote, @UnitEng, @AlternCost)";
SqlDataSource1.SelectCommand = "SELECT * FROM [" + tableInUse + "] ORDER BY [Code]";
SqlDataSource1.UpdateCommand = "UPDATE [" + tableInUse + "] SET [Code] = @Code, [Description] = @Description, [Bkgroup] = @Bkgroup, [Stgroup] = @Stgroup, [Quantity] = @Quantity, [BomNote] = @BomNote, [UnitEng] = @UnitEng, [AlternCost] = @AlternCost WHERE [Id] = @Id";
}
<
div
style
=
"width: 50%;height: 200px"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Width
=
"100%"
Height
=
"100%"
AutoGenerateColumns
=
"False"
OnNeedDataSource
=
"OnGridNeedDataSource"
>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"None"
>
<
Columns
>
<
telerik:GridBoundColumn
HeaderText
=
"Column 1"
UniqueName
=
"Column1"
DataField
=
"Column1"
HeaderStyle-Width
=
"100"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Column 2"
UniqueName
=
"Column2"
DataField
=
"Column2"
HeaderStyle-Width
=
"100"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Column 3"
UniqueName
=
"Column3"
DataField
=
"Column3"
HeaderStyle-Width
=
"100"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Column 4"
UniqueName
=
"Column4"
DataField
=
"Column4"
HeaderStyle-Width
=
"100"
/>
<
telerik:GridBoundColumn
HeaderText
=
"Column 5"
UniqueName
=
"Column5"
DataField
=
"Column5"
HeaderStyle-Width
=
"100"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
Scrolling
AllowScroll
=
"True"
UseStaticHeaders
=
"True"
FrozenColumnsCount
=
"2"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
</
div
>
<
script
>
function ResizeGrid(gridID)
{
var scrollArea = $get(gridID + "_GridData");
scrollArea.style.height = (157 + 17) + "px";
}
function OnGridCreated(sender, ev)
{
ResizeGrid(sender.ClientID);
}
</
script
>
<
telerik:RadScriptBlock
runat
=
"server"
>
<
script
>
window.onresize = function () { setTimeout(function() { ResizeGrid("<%=RadGrid1.ClientID%>"); }, 200) }
function ResizeGrid(gridID)
{
var scrollArea = $get(gridID + "_GridData");
scrollArea.style.height = (157 + 17) + "px";
$find(gridID).repaint();
}
</
script
>
</
telerik:RadScriptBlock
>