or
<
telerik:RadGrid
id
=
"rgdListLicences"
runat
=
"server"
Width
=
"100%"
OnNeedDataSource
=
"rgdListLicences_NeedDataSource"
GridLines
=
"None"
Skin
=
"eLicensing_paging"
EnableEmbeddedSkins
=
"false"
EnableViewState
=
"true"
>
<
ExportSettings
IgnorePaging
=
"true"
OpenInNewWindow
=
"true"
ExportOnlyData
=
"false"
>
<
Pdf
PageHeight
=
"210mm"
AllowPrinting
=
"true"
PageWidth
=
"297mm"
PageTitle
=
"Print Validations"
DefaultFontFamily
=
"Arial Unicode MS"
PageBottomMargin
=
"20mm"
PageTopMargin
=
"20mm"
PageLeftMargin
=
"20mm"
PageRightMargin
=
"20mm"
/>
</
ExportSettings
>
<
MasterTableView
RetrieveAllDataFields
=
"false"
CommandItemDisplay
=
"Top"
AutoGenerateColumns
=
"false"
>
<
CommandItemTemplate
>
<
telerik:radbutton
ID
=
"DownloadPDF"
AutoPostBack
=
"true"
CssClass
=
"pdfButton"
runat
=
"server"
Width
=
"10%"
Text
=
"Print Validations"
CommandName
=
"ExportToPdf"
/>
</
CommandItemTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"clientRef"
DataFormatString
=
"{0:dd/MM/yy}"
HeaderText
=
"Client Ref"
><
ItemStyle
Width
=
"12%"
VerticalAlign
=
"Top"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ServiceName"
HeaderText
=
"Service Name"
><
ItemStyle
Width
=
"28%"
VerticalAlign
=
"Top"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"commencementDate"
DataFormatString
=
"{0:dd/MM/yy}"
HeaderText
=
"Start Date"
><
ItemStyle
Width
=
"12%"
VerticalAlign
=
"Top"
/>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"validations"
HeaderText
=
"Validations"
SortExpression
=
"CompanyName"
>
<
ItemTemplate
>
<
telerik:radgrid
ID
=
"rgdValidations"
OnNeedDataSource
=
"rgdValidations_NeedDataSource"
BorderStyle
=
"None"
ShowHeader
=
"false"
runat
=
"server"
EnableViewState
=
"true"
>
<
MasterTableView
>
<
ItemStyle
Font-Size
=
"Smaller"
/>
<
AlternatingItemStyle
Font-Size
=
"Smaller"
/>
</
MasterTableView
>
</
telerik:radgrid
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
Protected Sub rgdValidations_NeedDataSource(ByVal sender As Object, ByVal e As GridNeedDataSourceEventArgs)
Dim RadGrid2 As RadGrid = CType(sender, RadGrid)
Dim item As GridDataItem = RadGrid2.NamingContainer
Dim validations As List(Of String) = CType(item.DataItem, LicencesLicence).validations
RadGrid2.DataSource = validations
End Sub
.rgRow,.rgRow td
{
height
:
30px
!important
;
cursor
:
pointer
;
background-color
:
#ffffff
;
border-bottom
:
solid
1px
#EDEDED
!important
;
}
.rgAltRow,.rgAltRow td
{
height
:
30px
!important
;
cursor
:
pointer
;
background-color
:
#ffffff
;
border-bottom
:
solid
1px
#EDEDED
;
/*border:none!important;
background-image : none!important;*/
}
<
telerik:RadComboBox
ID
=
"cboSKU"
runat
=
"server"
DataTextField
=
"STCode"
DataValueField
=
"STCode"
MarkFirstMatch
=
"true"
ShowToggleImage
=
"false"
EnableAutomaticLoadOnDemand
=
"true"
ShowMoreResultsBox
=
"true"
ItemsPerRequest
=
"30"
AutoPostBack
=
"true"
onselectedindexchanged
=
"cboSKU_SelectedIndexChanged"
>
if (RadAjaxManager1.IsAjaxRequest == false)
{
AddLogEntry();
}
if (ScriptManager.GetCurrent(Page).IsInAsyncPostBack == false)
{
AddLogEntry();
}
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Data.SqlClient;
using
System.Configuration;
using
System.Data;
using
Telerik.Web.UI;
using
System.IO;
public
partial
class
_Default : System.Web.UI.Page
{
public
DataTable table;
public
SqlDataAdapter sqlDataAdapter =
new
SqlDataAdapter();
SqlConnection conn =
new
SqlConnection(ConfigurationManager.ConnectionStrings[
"DoraConnectionString"
].ConnectionString);
SqlCommand command =
new
SqlCommand();
protected
void
Page_Load(
object
sender, EventArgs e)
{
if
(!IsPostBack)
{
}
}
protected
void
RadGrid1_NeedDataSource(
object
source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
command.Connection = conn;
string
selectQuery =
"Select * from Files"
;
table =
new
DataTable();
conn.Open();
try
{
//Select Query to populate the RadGrid with data from table Employees.
sqlDataAdapter.SelectCommand =
new
SqlCommand(selectQuery, conn);
sqlDataAdapter.Fill(table);
RadGrid1.DataSource = table;
}
finally
{
//Close the SqlConnection
conn.Close();
}
}
protected
void
RadGrid1_ItemCommand(
object
source, GridCommandEventArgs e)
{
if
(e.CommandName == RadGrid.PerformInsertCommandName)
{
RadUpload upload = (RadUpload)e.Item.FindControl(
"RadUpload1"
);
foreach
(UploadedFile f
in
upload.UploadedFiles)
{
f.SaveAs(Server.MapPath(
"./"
+ f.GetName()));
}
GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
//string EmployeeID = (insertedItem["EmployeeID"].Controls[0] as TextBox).Text;
string
FileName = (item[
"FileName"
].FindControl(
"RadUpload1"
)
as
RadUpload).UploadedFiles[0].GetName();
UploadedFile file = (item[
"FileName"
].FindControl(
"RadUpload1"
)
as
RadUpload).UploadedFiles[0];
int
Size = (
int
)file.InputStream.Length;
string
ContentType = GetFileContentType(FileName);
byte
[] bytes =
new
byte
[Size];
file.InputStream.Read(bytes, 0, (
int
)file.InputStream.Length);
DateTime Date = DateTime.Now;
try
{
//Open the SqlConnection
conn.Open();
//Update Query to insert into the database
string
insertQuery =
"INSERT into Files(FileName,FileData,Size,ContentType,Date) values(@FileName, @FileData,@Size, @ContentType, @Date)"
;
command.CommandText = insertQuery;
command.Connection = conn;
command.Parameters.AddWithValue(
"@FileName"
, FileName);
command.Parameters.AddWithValue(
"@FileData"
, bytes);
command.Parameters.AddWithValue(
"@Size"
, Size);
command.Parameters.AddWithValue(
"@ContentType"
, ContentType);
command.Parameters.AddWithValue(
"@Date"
, Date);
command.ExecuteNonQuery();
//Close the SqlConnection
conn.Close();
}
catch
(Exception ex)
{
RadGrid1.Controls.Add(
new
LiteralControl(
"Unable to insert Files. Reason: "
+ ex.Message));
e.Canceled =
true
;
}
}
if
(e.CommandName == RadGrid.UpdateCommandName)
{
GridEditFormItem item = (GridEditFormItem)e.Item;
//string EmployeeID = (insertedItem["EmployeeID"].Controls[0] as TextBox).Text;
string
FileName = (item[
"FileName"
].FindControl(
"RadUpload1"
)
as
RadUpload).UploadedFiles[0].GetName();
UploadedFile file = (item[
"FileName"
].FindControl(
"RadUpload1"
)
as
RadUpload).UploadedFiles[0];
int
Size = (
int
)file.InputStream.Length;
string
ContentType = GetFileContentType(FileName);
byte
[] bytes =
new
byte
[Size];
file.InputStream.Read(bytes, 0, (
int
)file.InputStream.Length);
DateTime Date = DateTime.Now;
try
{
//Open the SqlConnection
conn.Open();
//Update Query to insert into the database
string
insertQuery =
"update Files set FileName=@FileName, FileData=@FileData, Size=@Size, ContentType=@ContentType, Date=@Date where ID=@ID"
;
command.CommandText = insertQuery;
command.Connection = conn;
command.Parameters.AddWithValue(
"@FileName"
, FileName);
command.Parameters.AddWithValue(
"@FileData"
, bytes);
command.Parameters.AddWithValue(
"@Size"
, Size);
command.Parameters.AddWithValue(
"@ContentType"
, ContentType);
command.Parameters.AddWithValue(
"@Date"
, Date);
command.Parameters.AddWithValue(
"@ID"
, item.GetDataKeyValue(
"ID"
));
command.ExecuteNonQuery();
//Close the SqlConnection
conn.Close();
}
catch
(Exception ex)
{
RadGrid1.Controls.Add(
new
LiteralControl(
"Unable to update Files. Reason: "
+ ex.Message));
e.Canceled =
true
;
}
}
}
protected
void
RadGrid1_ItemCreated(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridDataItem)
{
LinkButton lnk = (e.Item
as
GridDataItem)[
"Preview"
].Controls[0]
as
LinkButton;
lnk.OnClientClick =
"Preview("
+ (e.Item
as
GridDataItem).GetDataKeyValue(
"ID"
) +
"); return false;"
;
}
}
private
string
GetFileContentType(
string
filename)
{
string
contentType =
string
.Empty;
int
indexOfDot = filename.LastIndexOf(
"."
);
if
(indexOfDot > 0)
{
++indexOfDot;
string
ext = filename.Substring(indexOfDot, (filename.Length - indexOfDot));
if
(!
string
.IsNullOrEmpty(ext))
{
switch
(ext.ToLower().Trim())
{
case
"doc"
:
case
"docx"
:
contentType =
"application/msword"
;
break
;
case
"pdf"
:
contentType =
"application/pdf"
;
break
;
case
"xls"
:
case
"xlsx"
:
contentType =
"application/ms-excel"
;
break
;
case
"rar"
:
contentType =
"application/winrar"
;
break
;
case
"txt"
:
contentType =
"text/plain"
;
break
;
case
"gif"
:
contentType =
"image/gif"
;
break
;
case
"jpeg"
:
case
"jpg"
:
contentType =
"image/jpeg"
;
break
;
case
"png"
:
contentType =
"image/x-png"
;
break
;
case
"tif"
:
contentType =
"image/tiff"
;
break
;
case
"bmp"
:
contentType =
"image/x-ms-bmp"
;
break
;
default
:
contentType =
"application/octet-stream"
;
break
;
}
}
}
return
contentType;
}
}