I have been searching all day to solve this problem and I am still at a loss.
I have a Grid that contains two detail tables linked to it, one of the Gallery allows the user to upload images to a specfic folder
for each property. Which names happens to be the primaryID of the Master Grid. However I cannot get it to insert a new record as i have been unable to access the primary key and therefore the upload component does not target the correct folder.
Any Help would be appreciated.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="propertyadmin.aspx.cs" Inherits="Default2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<
title
></
title
>
</
head
>
<
body
>
<
form
id
=
"form1"
runat
=
"server"
>
<
asp:Label
ID
=
"Label1"
ForeColor
=
"Red"
runat
=
"server"
/>
<
asp:SqlDataSource
ID
=
"SqlDataSourceTransportOptions"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_transport_option]"></
asp:SqlDataSource
>
<
telerik:RadStyleSheetManager
ID
=
"RadStyleSheetManager1"
runat
=
"server"
>
</
telerik:RadStyleSheetManager
>
<
div
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
>
<
Scripts
>
<%--Needed for JavaScript IntelliSense in VS2010--%>
<%--For VS2008 replace RadScriptManager with ScriptManager--%>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.Core.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQuery.js"
/>
<
asp:ScriptReference
Assembly
=
"Telerik.Web.UI"
Name
=
"Telerik.Web.UI.Common.jQueryInclude.js"
/>
</
Scripts
>
</
telerik:RadScriptManager
>
<
script
type
=
"text/javascript"
>
//Put your JavaScript code here.
</
script
>
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
//
<![CDATA[
//On insert and update buttons click temporarily disables ajax to perform upload actions
function conditionalPostback(sender, eventArgs) {
var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
if (eventArgs.get_eventTarget().match(theRegexp)) {
var upload = $find(window['UploadId']);
//AJAX is disabled only if file is selected for upload
if (!upload || upload.getFileInputs()[0].value != "") {
eventArgs.set_enableAjax(false);
}
}
}
function validateRadUpload(source, e) {
e.IsValid = false;
var upload = $find(source.parentNode.getElementsByTagName('div')[0].id);
var inputs = upload.getFileInputs();
for (var i = 0; i < inputs.length; i++) {
//check for empty string or invalid extension
if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
e.IsValid = true;
break;
}
}
}
// ]]>
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxPanel
ID
=
"RadAjaxPanel1"
runat
=
"server"
ClientEvents-OnRequestStart
=
"conditionalPostback"
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceProperty"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_property]"
DeleteCommand="DELETE FROM [tbl_property] WHERE [Property_ID] = @Property_ID"
InsertCommand="INSERT INTO [tbl_property] ([Property_Title], [Short_Description], [Tenure], [Plot_Size], [Building_Gross_Internal], [Building_Net_Internal], [Location], [Description], [Accommodation], [Address], [Post_Code], [Price], [Geographical_Area], [Type], [Status], [date_Added], [thumbnail], [date_sold]) VALUES (@Property_Title, @Short_Description, @Tenure, @Plot_Size, @Building_Gross_Internal, @Building_Net_Internal, @Location, @Description, @Accommodation, @Address, @Post_Code, @Price, @Geographical_Area, @Type, @Status, @date_Added, @thumbnail, @date_sold)"
UpdateCommand="UPDATE [tbl_property] SET [Property_Title] = @Property_Title, [Short_Description] = @Short_Description, [Tenure] = @Tenure, [Plot_Size] = @Plot_Size, [Building_Gross_Internal] = @Building_Gross_Internal, [Building_Net_Internal] = @Building_Net_Internal, [Location] = @Location, [Description] = @Description, [Accommodation] = @Accommodation, [Address] = @Address, [Post_Code] = @Post_Code, [Price] = @Price, [Geographical_Area] = @Geographical_Area, [Type] = @Type, [Status] = @Status, [date_Added] = @date_Added, [thumbnail] = @thumbnail, [date_sold] = @date_sold WHERE [Property_ID] = @Property_ID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Property_ID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"Property_Title"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Short_Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Tenure"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Plot_Size"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Building_Gross_Internal"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Building_Net_Internal"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Location"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Accommodation"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Post_Code"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Price"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"Geographical_Area"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Type"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Status"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"date_Added"
Type
=
"DateTime"
/>
<
asp:SessionParameter
Name
=
"thumbnail"
SessionField
=
"DataCS"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"date_sold"
Type
=
"DateTime"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"Property_Title"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Short_Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Tenure"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Plot_Size"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Building_Gross_Internal"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Building_Net_Internal"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Location"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Accommodation"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Post_Code"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Price"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"Geographical_Area"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Type"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Status"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"date_Added"
Type
=
"DateTime"
/>
<
asp:SessionParameter
Name
=
"thumbnail"
SessionField
=
"DataCS"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"date_sold"
Type
=
"DateTime"
/>
<
asp:Parameter
Name
=
"Property_ID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceArea"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_geographic_area]"></
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceType"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_property_type]"></
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceStatus"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_status]"></
asp:SqlDataSource
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceTenure"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_tenure]"></
asp:SqlDataSource
>
<
telerik:RadGrid
runat
=
"server"
ID
=
"RadGrid1"
AllowPaging
=
"True"
AllowSorting
=
"True"
AutoGenerateColumns
=
"False"
Width
=
"97%"
DataSourceID
=
"SqlDataSourceProperty"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowAutomaticDeletes
=
"True"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
Skin
=
"Web20"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
ShowStatusBar
=
"True"
GridLines
=
"None"
AutoGenerateDeleteColumn
=
"True"
AutoGenerateEditColumn
=
"True"
CellSpacing
=
"0"
AutoGenerateHierarchy
=
"True"
OnSelectedIndexChanged
=
"RadGrid1_SelectedIndexChanged"
>
<
ClientSettings
>
<
Selecting
AllowRowSelect
=
"True"
/>
</
ClientSettings
>
<
MasterTableView
AutoGenerateColumns
=
"False"
DataKeyNames
=
"Property_ID"
CommandItemDisplay
=
"TopAndBottom"
NoDetailRecordsText
=
"No records to display."
DataSourceID
=
"SqlDataSourceProperty"
>
<
DetailTables
>
<
telerik:GridTableView
runat
=
"server"
DataSourceID
=
"SqlDataSourceTransport"
Caption
=
"Transport Opions"
AllowPaging
=
"False"
AllowSorting
=
"False"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"transportOptionID,property_ID"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"property_ID"
MasterKeyField
=
"Property_ID"
/>
</
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridDropDownColumn
DataField
=
"option_ID"
DataSourceID
=
"SqlDataSourceTransportOptions"
FilterControlAltText
=
"Filter transportOptionDD column"
HeaderText
=
"Transport Option"
ListTextField
=
"transtport_type"
ListValueField
=
"transport_option_ID"
UniqueName
=
"transportOptionDD"
>
</
telerik:GridDropDownColumn
>
<
telerik:GridBoundColumn
DataField
=
"description"
FilterControlAltText
=
"Filter description column"
HeaderText
=
"Description"
UniqueName
=
"description"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"property_ID"
Display
=
"False"
FilterControlAltText
=
"Filter property_ID column"
HeaderText
=
"Property ID"
ReadOnly
=
"True"
UniqueName
=
"property_ID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"transportOptionID"
FilterControlAltText
=
"Filter propertyTransportOptionID column"
HeaderText
=
"Property Transport ID"
ReadOnly
=
"True"
UniqueName
=
"propertyTransportOptionID"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
<
telerik:GridTableView
runat
=
"server"
DataKeyNames
=
"galleryImageID,propertyID"
DataSourceID
=
"SqlDataSourceGallery"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowSorting
=
"False"
CommandItemDisplay
=
"Top"
>
<
ParentTableRelation
>
<
telerik:GridRelationFields
DetailKeyField
=
"PropertyId"
MasterKeyField
=
"Property_ID"
/>
</
ParentTableRelation
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
/>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"FolderName"
UniqueName
=
"FolderName"
DataField
=
"PropertyID"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"LblFolder"
Text='<%# Eval("PropertyId") %>'></
asp:Label
>
</
ItemTemplate
>
<
editItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"LblFolder"
Text='<%# Eval("PropertyId") %>'></
asp:Label
>
</
editItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"Filename"
FilterControlAltText
=
"Filter Filename column"
HeaderText
=
"Filename"
UniqueName
=
"Filename"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Height"
FilterControlAltText
=
"Filter Height column"
HeaderText
=
"Height"
UniqueName
=
"Height"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"width"
FilterControlAltText
=
"Filter width column"
HeaderText
=
"Width"
UniqueName
=
"width"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
DataField
=
"filename"
FilterControlAltText
=
"Filter Image column"
HeaderText
=
"Image"
UniqueName
=
"Image"
>
<
EditItemTemplate
>
<
telerik:RadUpload
ID
=
"RadUpload2"
Runat
=
"server"
AllowedFileExtensions
=
".jpg,.png,.gif,.wmv"
ControlObjectsVisibility
=
"None"
InitialFileInputsCount
=
"1"
MaxFileInputsCount
=
"1"
MaxFileSize
=
"10000000"
Skin
=
"Windows7"
OverwriteExistingFiles
=
"True"
>
</
telerik:RadUpload
>
</
EditItemTemplate
>
<
ItemTemplate
>
<
img
src
=
"media/gallery/<%# Eval("
PropertyId") %>/<%# Eval("Filename") %>" alt="Image" />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"PropertyID"
Display
=
"False"
FilterControlAltText
=
"Filter PropertyID column"
HeaderText
=
"Property ID"
ReadOnly
=
"True"
UniqueName
=
"PropertyID"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Size"
Display
=
"False"
FilterControlAltText
=
"Filter size column"
HeaderText
=
"Size"
UniqueName
=
"size"
Visible
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"GalleryImageID"
Display
=
"False"
FilterControlAltText
=
"Filter galleryImageID column"
HeaderText
=
"Image"
ReadOnly
=
"True"
UniqueName
=
"galleryImageID"
>
</
telerik:GridBoundColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
>
</
EditColumn
>
</
EditFormSettings
>
</
telerik:GridTableView
>
</
DetailTables
>
<
CommandItemSettings
ExportToPdfText
=
"Export to PDF"
></
CommandItemSettings
>
<
RowIndicatorColumn
FilterControlAltText
=
"Filter RowIndicator column"
>
</
RowIndicatorColumn
>
<
ExpandCollapseColumn
FilterControlAltText
=
"Filter ExpandColumn column"
Visible
=
"True"
>
</
ExpandCollapseColumn
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"Property_ID"
FilterControlAltText
=
"Filter Property_ID column"
HeaderText
=
"Property_ID"
SortExpression
=
"Property_ID"
UniqueName
=
"Property_ID"
DataType
=
"System.Int32"
ReadOnly
=
"True"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Thumbnail"
UniqueName
=
"Upload"
DataField
=
"thumbnail"
>
<
ItemTemplate
>
<
img
src
=
"media/thumbnails/<%# Eval("
Thumbnail") %>" alt="thumbnail" />
</
ItemTemplate
>
<
EditItemTemplate
>
<
telerik:RadUpload
ID
=
"RadUpload1"
Runat
=
"server"
AllowedFileExtensions
=
".jpg,.png,.gif,.wmv"
ControlObjectsVisibility
=
"None"
InitialFileInputsCount
=
"1"
MaxFileInputsCount
=
"1"
MaxFileSize
=
"10000000"
Skin
=
"Windows7"
OverwriteExistingFiles
=
"True"
>
</
telerik:RadUpload
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"Property_Reference"
FilterControlAltText
=
"Filter Property_Reference column"
HeaderText
=
"Property_Reference"
SortExpression
=
"Property_Reference"
UniqueName
=
"Property_Reference"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Property_Title"
FilterControlAltText
=
"Filter Property_Title column"
HeaderText
=
"Property_Title"
SortExpression
=
"Property_Title"
UniqueName
=
"Property_Title"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Short_Description"
FilterControlAltText
=
"Filter Short_Description column"
HeaderText
=
"Short_Description"
SortExpression
=
"Short_Description"
UniqueName
=
"Short_Description"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Plot_Size"
FilterControlAltText
=
"Filter Plot_Size column"
HeaderText
=
"Plot_Size"
SortExpression
=
"Plot_Size"
UniqueName
=
"Plot_Size"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Building_Gross_Internal"
FilterControlAltText
=
"Filter Building_Gross_Internal column"
HeaderText
=
"Building_Gross_Internal"
SortExpression
=
"Building_Gross_Internal"
UniqueName
=
"Building_Gross_Internal"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Building_Net_Internal"
FilterControlAltText
=
"Filter Building_Net_Internal column"
HeaderText
=
"Building_Net_Internal"
SortExpression
=
"Building_Net_Internal"
UniqueName
=
"Building_Net_Internal"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Location"
FilterControlAltText
=
"Filter Location column"
HeaderText
=
"Location"
SortExpression
=
"Location"
UniqueName
=
"Location"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Description"
FilterControlAltText
=
"Filter Description column"
HeaderText
=
"Description"
SortExpression
=
"Description"
UniqueName
=
"Description"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Accommodation"
FilterControlAltText
=
"Filter Accommodation column"
HeaderText
=
"Accommodation"
SortExpression
=
"Accommodation"
UniqueName
=
"Accommodation"
Display
=
"False"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Address"
FilterControlAltText
=
"Filter Address column"
HeaderText
=
"Address"
SortExpression
=
"Address"
UniqueName
=
"Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Post_Code"
FilterControlAltText
=
"Filter Post_Code column"
HeaderText
=
"Post_Code"
SortExpression
=
"Post_Code"
UniqueName
=
"Post_Code"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Price"
FilterControlAltText
=
"Filter Price column"
HeaderText
=
"Price"
SortExpression
=
"Price"
UniqueName
=
"Price"
DataType
=
"System.Decimal"
>
</
telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Geographical_Area"
DataSourceID
=
"SqlDataSourceArea"
Display
=
"False"
FilterControlAltText
=
"Filter geoArea column"
HeaderText
=
"Geographic Area"
ListTextField
=
"area"
ListValueField
=
"geographic_ID"
UniqueName
=
"geoArea"
>
</
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Status"
DataSourceID
=
"SqlDataSourceStatus"
Display
=
"False"
FilterControlAltText
=
"Filter Status column"
HeaderText
=
"Status"
ListTextField
=
"status_type"
ListValueField
=
"status_id"
UniqueName
=
"Status"
>
</
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Tenure"
DataSourceID
=
"SqlDataSourceTenure"
FilterControlAltText
=
"Filter Tenure column"
HeaderText
=
"Tenure"
ListTextField
=
"tenure_type"
ListValueField
=
"tenure_ID"
UniqueName
=
"Tenure"
>
</
telerik:GridDropDownColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Type"
DataSourceID
=
"SqlDataSourceType"
FilterControlAltText
=
"Filter Type column"
HeaderText
=
"Type"
ListTextField
=
"property_type"
ListValueField
=
"type_ID"
UniqueName
=
"Type"
>
</
telerik:GridDropDownColumn
>
<
telerik:GridDateTimeColumn
DataField
=
"Date_Added"
FilterControlAltText
=
"Filter DataAdded column"
HeaderText
=
"Date Added"
UniqueName
=
"DataAdded"
>
</
telerik:GridDateTimeColumn
>
<
telerik:GridDateTimeColumn
DataField
=
"date_sold"
FilterControlAltText
=
"Filter dateSold column"
HeaderText
=
"Date Sold"
UniqueName
=
"dateSold"
>
</
telerik:GridDateTimeColumn
>
</
Columns
>
<
EditFormSettings
>
<
EditColumn
FilterControlAltText
=
"Filter EditCommandColumn column"
UniqueName
=
"EditCommandColumn1"
></
EditColumn
>
</
EditFormSettings
>
</
MasterTableView
>
<
FilterMenu
EnableImageSprites
=
"False"
></
FilterMenu
>
<
HeaderContextMenu
CssClass
=
"GridContextMenu GridContextMenu_Default"
></
HeaderContextMenu
>
</
telerik:RadGrid
>
</
telerik:RadAjaxPanel
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceTransport"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [tbl_property_transport_options] WHERE ([property_ID] = @property_ID)"
DeleteCommand="DELETE FROM [tbl_property_transport_options] WHERE [transportOptionID] = @transportOptionID"
InsertCommand="INSERT INTO [tbl_property_transport_options] ([property_ID], [option_ID], [description]) VALUES (@property_ID, @option_ID, @description)"
UpdateCommand="UPDATE [tbl_property_transport_options] SET [property_ID] = @property_ID, [option_ID] = @option_ID, [description] = @description WHERE [transportOptionID] = @transportOptionID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"transportOptionID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"property_ID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"option_ID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"description"
Type
=
"String"
/>
</
InsertParameters
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"RadGrid1"
Name
=
"property_ID"
PropertyName
=
"SelectedValue"
Type
=
"Int32"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"property_ID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"option_ID"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"description"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"transportOptionID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
</
div
>
<
asp:SqlDataSource
ID
=
"SqlDataSourceGallery"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:proprovsConnectionString %>"
SelectCommand="SELECT * FROM [gallery] WHERE ([PropertyId] = @PropertyId)"
DeleteCommand="DELETE FROM [gallery] WHERE [GalleryImageID] = @GalleryImageID"
InsertCommand="INSERT INTO [gallery] ([PropertyId], [Filename], [Width], [Height], [Size]) VALUES (@PropertyId, @Filename, @Width, @Height, @Size)"
UpdateCommand="UPDATE [gallery] SET [PropertyId] = @PropertyId, [Filename] = @Filename, [Width] = @Width, [Height] = @Height, [Size] = @Size WHERE [GalleryImageID] = @GalleryImageID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"GalleryImageID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"PropertyId"
Type
=
"Int32"
/>
<
asp:SessionParameter
Name
=
"Filename"
SessionField
=
"DataCS"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Width"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Height"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Size"
Type
=
"Int32"
/>
</
InsertParameters
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"RadGrid1"
Name
=
"PropertyId"
PropertyName
=
"SelectedValue"
Type
=
"Int32"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"PropertyId"
Type
=
"Int32"
/>
<
asp:SessionParameter
Name
=
"Filename"
SessionField
=
"DataCS"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Width"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Height"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Size"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"GalleryImageID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
</
form
>
</
body
>
</
html
>
using System;
using System.IO;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
using Telerik.Web.UI;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
//Display te primary key value of the selected row.
Label1.Text = "The primary key value of the selected row is " +
RadGrid1.SelectedValue.ToString() + ".";
}
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
InitializeUpdateParameter((RadUpload)e.Item.FindControl("RadUpload1"));
RadUpload upload = e.Item.FindControl("RadUpload2") as RadUpload;
string foldername = (e.Item.FindControl("LblFolder") as Label).Text;
InitializeUpdateParameterGallery(upload, foldername);
}
protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e)
{
InitializeUpdateParameter((RadUpload)e.Item.FindControl("RadUpload1"));
RadUpload upload = e.Item.FindControl("RadUpload2") as RadUpload;
GridEditableItem editedItem = e.Item as GridEditableItem;
string foldername = "";
InitializeUpdateParameterGallery(upload, foldername);
}
private void InitializeUpdateParameterGallery(RadUpload currentUpload, string foldername)
{
if (currentUpload != null && currentUpload.UploadedFiles.Count > 0)
{
byte[] data = new byte[currentUpload.UploadedFiles[0].ContentLength];
currentUpload.UploadedFiles[0].InputStream.Read(data, 0, data.Length);
Session["DataCS"] = currentUpload.UploadedFiles[0].GetName();
string target = Server.MapPath("~/media/gallery/" + foldername + "/" );
System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
UploadedFile file = currentUpload.UploadedFiles[0];
using (Bitmap originalImage = new Bitmap(file.InputStream))
{
decimal newWidth, newHeight;
newWidth = 411;
newHeight = 0; // Will get calculated
scaleImage(originalImage.Width, originalImage.Height, ref newWidth, ref newHeight);
using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(Convert.ToInt32(newWidth), Convert.ToInt32(newHeight), thumbnailImageAbortDelegate, IntPtr.Zero))
{
string thumbnailFileName = Path.Combine(target, string.Format("{0}{1}", file.GetNameWithoutExtension(), file.GetExtension()));
thumbnail.Save(thumbnailFileName);
}
}
}
}
private void InitializeUpdateParameter(RadUpload currentUpload)
{
if (currentUpload != null && currentUpload.UploadedFiles.Count > 0)
{
byte[] data = new byte[currentUpload.UploadedFiles[0].ContentLength];
currentUpload.UploadedFiles[0].InputStream.Read(data, 0, data.Length);
Session["DataCS"] = currentUpload.UploadedFiles[0].GetName();
string target = Server.MapPath("~/media/thumbnails");
System.Drawing.Image.GetThumbnailImageAbort thumbnailImageAbortDelegate = new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback);
UploadedFile file = currentUpload.UploadedFiles[0];
using (Bitmap originalImage = new Bitmap(file.InputStream))
{
decimal newWidth, newHeight;
newWidth = 125;
newHeight = 0; // Will get calculated
scaleImage(originalImage.Width, originalImage.Height, ref newWidth, ref newHeight);
using (System.Drawing.Image thumbnail = originalImage.GetThumbnailImage(Convert.ToInt32(newWidth), Convert.ToInt32(newHeight), thumbnailImageAbortDelegate, IntPtr.Zero))
{
string thumbnailFileName = Path.Combine(target, string.Format("{0}_thumb{1}", file.GetNameWithoutExtension(), file.GetExtension()));
thumbnail.Save(thumbnailFileName);
}
}
}
}
public bool ThumbnailCallback()
{
return false;
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if(RadGrid1.SelectedItems.Count != 0) {
Response.Write(RadGrid1.SelectedItems[0].OwnerTableView.DataKeyValues[RadGrid1.SelectedItems[0].ItemIndex]["Property_ID"]);
}
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
RadUpload upload = (RadUpload)e.Item.FindControl("RadUpload1");
if(upload != null) {
RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID));
}
upload = (RadUpload)e.Item.FindControl("RadUpload2");
if (upload != null)
{
RadAjaxPanel1.ResponseScripts.Add(string.Format("window['UploadId'] = '{0}';", upload.ClientID));
}
}
}
#region GetTelerikGridSelections
public ArrayList GetTelerikGridSelections(Telerik.Web.UI.RadGrid grid)
{
ArrayList selectedItems = new ArrayList();
if (grid.MasterTableView.DataKeyNames.Length > 0)
{
string key = grid.MasterTableView.DataKeyNames[0];
for (int i = 0; i < grid.SelectedItems.Count; i++)
{
selectedItems.Add(grid.MasterTableView.DataKeyValues[grid.SelectedItems[i].ItemIndex][key]);
}
}
return selectedItems;
}
#endregion
public void scaleImage(decimal currentWidth, decimal currentHeight, ref decimal newWidth, ref decimal newHeight)
{
// Supply either newWidth or newHeight, not both
decimal height = 0;
decimal ratio = 0;
if (newWidth == 0)
{ // Scale based on new height
ratio = currentWidth / currentHeight;
newWidth = newHeight * ratio;
}
else
{ // Scale based on new width
ratio = currentHeight / currentWidth;
newHeight = newWidth * ratio;
}
}
}