Telerik RadGrid Demo

List Page 

Html code:

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Videos.aspx.vb" Inherits="AwcWeb.Videos" %>



<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<%@ Register Src="LeftControl1.ascx" TagName="LeftControl1" TagPrefix="uc1" %>

<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!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 id="Head1" runat="server">

    <title>視頻管理</title>

    <link href="css/Global.css" rel="stylesheet" type="text/css" />

    <script src="Scripts/RadCommon.js" type="text/javascript"></script>

    <style>

        ul#nav li a#nav03

        {

            background: #fff;

            color: #000;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

        <Scripts>

            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js">

            </asp:ScriptReference>

            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js">

            </asp:ScriptReference>

            <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js">

            </asp:ScriptReference>

        </Scripts>

    </telerik:RadScriptManager>

    <div class="header">

        <div class="roxvell_logo">

            <img width="191" height="24" style="margin-top: 35px; float: right;" src="images/logo.png">

        </div>

    </div>

    <div style="width: 1024px; height: 720px; margin: 0 auto; overflow: hidden;">

        <uc1:LeftControl1 ID="leftControl1" runat="server" />

        <div style="width: 874px; height: 720px; float: left;">

            <telerik:RadMenu ID="RadMenu1" runat="server" Skin="Default" OnClientItemClicked="OnClientItemClicked"

                Width="100%">

                <CollapseAnimation Duration="200" Type="OutQuint" />

                <Items>

                    <telerik:RadMenuItem runat="server" Text="新增" Style="cursor: pointer;" Value="New" />

                    <telerik:RadMenuItem runat="server" Text="編輯" Style="cursor: pointer;" Value="Edit" />

                    <telerik:RadMenuItem runat="server" Text="刪除" Style="cursor: pointer;" Value="Del" />

                </Items>

            </telerik:RadMenu>

            <div style="width: 100%; height: 664px; overflow: hidden;">

                <telerik:RadGrid ID="radGrid1" runat="server" Skin="Default" AutoGenerateColumns="False"

                    AllowMultiRowSelection="false" GridLines="None" PageSize="7" AllowPaging="True"

                    Height="664px">

                    <MasterTableView ClientDataKeyNames="VideoID" DataKeyNames="VideoID">

                        <NoRecordsTemplate>

                            <h4 style="color: #336699; font-weight: bold; font-size: 14px; height: 40px; line-height: 40px;

                                width: 100%; text-align: center;">

                                暫無數據.</h4>

                        </NoRecordsTemplate>

                        <Columns>

                            <telerik:GridTemplateColumn HeaderText="" UniqueName="Picture">

                                <ItemTemplate>

                                    <table cellpadding="0" cellspacing="0" border="0" style="width: 70px; height: 66px;">

                                        <tr valign="middle" align="center">

                                            <td valign="middle" align="center">

                                                <asp:Image ID="imgPic" runat="server" />

                                            </td>

                                        </tr>

                                    </table>

                                </ItemTemplate>

                                <HeaderStyle HorizontalAlign="Center" Width="10%" Height="66px" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridTemplateColumn>

                            <telerik:GridBoundColumn HeaderText="繁體標題" DataField="Title_tc" UniqueName="Title_tc">

                                <HeaderStyle HorizontalAlign="Center" Width="20%" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn HeaderText="簡體標題" DataField="Title_sc" UniqueName="Title_sc">

                                <HeaderStyle HorizontalAlign="Center" Width="20%" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn HeaderText="英文標題" DataField="Title_en" UniqueName="Title_en">

                                <HeaderStyle HorizontalAlign="Center" Width="20%" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridBoundColumn>

                            <telerik:GridBoundColumn HeaderText="日文標題" DataField="Title_jp" UniqueName="Title_jp">

                                <HeaderStyle HorizontalAlign="Center" Width="20%" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridBoundColumn>

                            <telerik:GridTemplateColumn HeaderText="" UniqueName="">

                                <ItemTemplate>

                                    <asp:Button ID="btnPublish" runat="server" Text="發佈" CommandName="Publish" CommandArgument='<%#Eval("VideoID") %>'

                                        OnClientClick="if(!confirm('是否發佈該視頻?')) return false;" Style="width: 66px;" />

                                    <asp:Button ID="btnCancelPublish" runat="server" Text="取消發佈" CommandName="CancelPublish"

                                        Style="width: 66px;" CommandArgument='<%#Eval("VideoID") %>' OnClientClick="if(!confirm('該視頻是否取消發佈?')) return false;" />

                                </ItemTemplate>

                                <HeaderStyle HorizontalAlign="Center" Width="10%" />

                                <ItemStyle HorizontalAlign="Center" />

                            </telerik:GridTemplateColumn>

                        </Columns>

                    </MasterTableView>

                    <PagerStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"

                        Font-Underline="False" ForeColor="#336699" Mode="NumericPages" Wrap="True" />

                    <SelectedItemStyle ForeColor="GreenYellow" />

                    <ClientSettings AllowColumnsReorder="True" ReorderColumnsOnClient="True">

                        <Selecting AllowRowSelect="True" />

                        <Scrolling AllowScroll="true" UseStaticHeaders="true" />

                        <ClientEvents OnRowDblClick="RowDblClick" />

                    </ClientSettings>

                </telerik:RadGrid>

            </div>

            <div style="text-align: right; width: 100%; clear: both; border-top: 1px solid #828282;

                padding-top: 8px;">

                <div style="width: 50px; height: 20px; float: right;">

                </div>

                <webdiyer:AspNetPager ID="AspNetPager1" runat="server" CurrentPageButtonStyle="FONT-SIZE: 12px;color:red"

                    FirstPageText="" LastPageText="" NextPageText="下一頁" NumericButtonCount="5" PrevPageText="上一頁"

                    PrevNextButtonsStyle="font-size:12px" ShowPageIndexBox="never">

                </webdiyer:AspNetPager>

            </div>

        </div>

    </div>

    <div class="footer" style="clear: both;">

    </div>

    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">

        <AjaxSettings>

            <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">

                <UpdatedControls>

                    <telerik:AjaxUpdatedControl ControlID="RadMenu1" />

                    <telerik:AjaxUpdatedControl ControlID="AspNetPager1" />

                    <telerik:AjaxUpdatedControl ControlID="radGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

                </UpdatedControls>

            </telerik:AjaxSetting>

            <telerik:AjaxSetting AjaxControlID="AspNetPager1">

                <UpdatedControls>

                    <telerik:AjaxUpdatedControl ControlID="RadMenu1" />

                    <telerik:AjaxUpdatedControl ControlID="AspNetPager1" />

                    <telerik:AjaxUpdatedControl ControlID="radGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />

                </UpdatedControls>

            </telerik:AjaxSetting>

        </AjaxSettings>

    </telerik:RadAjaxManager>

    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" Width="330px"

        Height="100px">

        <img alt="Loading..." src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading.gif") %>'

            style="border: 0px;" />

    </telerik:RadAjaxLoadingPanel>

    <telerik:RadWindowManager Style="z-index: 900001" ID="RadWindowManager1" runat="server"

        Behavior="Close" Modal="true" Skin="Default" VisibleStatusbar="false" ShowContentDuringLoad="false">

    </telerik:RadWindowManager>

    <telerik:RadCodeBlock runat="server" ID="CodeBlock1">

        <script type="text/javascript">

            var width = 716;

            var height = 380;





            function OnClientItemClicked(sender, args) {

                var itemValue = args.get_item().get_value();

                switch (itemValue) {

                    case "New":

                        InsertCommand();

                        break;

                    case "Edit":

                        UpdateCommand();

                        break;

                    case "Del":

                        MultiRowDel();

                        break;

                }

            }



            function MultiRowDel() {

                arrayArticleID = "";

                var items = $find("<%=radGrid1.ClientID %>").get_masterTableView().get_selectedItems();



                if (items.length <= 0) {

                    window.radalert('請先選擇一張視頻,再進行刪除操作 !', 330, 100, '資訊');

                    return false;

                }

                else {

                    window.radconfirm('確定要刪除該視頻嗎 ?', confirmCallBackFn, 330, 100, null, "刪除");

                }



            }



            function confirmCallBackFn(arg) {

                if (arg) {

                    $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("Delete#");

                }

            }



            function MultiRowDelFn(arg) {

                if (arg) {

                    $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("Delete#" + arrayArticleID)

                }

            }



            function InsertCommand() {

                var url = "VideoItem.aspx?EditMode=New";

                var title = "新增視頻";



                OpenWin(url, title, width, height, "EditWindow");

            }



            function UpdateCommand() {

                var grid = $find("<%=radGrid1.ClientID %>");

                var MasterTable = grid.get_masterTableView();

                var selectedItems = MasterTable.get_selectedItems();

                if (selectedItems.length > 0) {

                    var row = selectedItems[0];

                    var strselectid = row.getDataKeyValue("VideoID");

                    var url = "VideoItem.aspx?VideoID=" + strselectid + "&EditMode=Edit";

                    var title = "修改視頻";



                    OpenWin(url, title, width, height, "EditWindow");

                }

                else {

                    window.radalert('請先選擇一個視頻,再進行修改操作 !', 330, 100, '資訊');

                }

            }



            function refreshGrid(arg, EditType) {

                if (EditType == "1") {

                    if (arg == "succeed") {

                        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("New#" + EditType);

                    }

                    else {

                        window.radalert('新增視頻失敗 !', 330, 100, '資訊');

                    }

                }

                else if (EditType == "2") {

                    if (arg == "succeed") {

                        $find("<%=RadAjaxManager1.ClientID %>").ajaxRequest("Edit#" + EditType);

                    }

                    else {

                        window.radalert('修改視頻失敗 !', 330, 100, '資訊');

                    }

                }

            }

            function RowDblClick(sender, eventArgs) {

                UpdateCommand();

            }

        </script>

    </telerik:RadCodeBlock>

    </form>

</body>

</html>

.net code:

Imports AWC.AndyVideosObj.AndyVideosObjEntry

Imports Telerik.Web.UI





Public Class Videos

    Inherits System.Web.UI.Page



    Private m_ocolAndyVideosObj As colAndyVideosObj

    Private Const intPageSize As Integer = 7



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        If Not IsPostBack Then

            If Session.Item("UserID") Is Nothing Then

                Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "window.location.href='Login.aspx';", True)

            End If



            AspNetPager1.PageSize = intPageSize

            BindData(1)

        End If

    End Sub



    Protected Sub AspNetPager1_PageChanged(ByVal sender As Object, ByVal e As EventArgs) Handles AspNetPager1.PageChanged

        BindData(AspNetPager1.CurrentPageIndex)

    End Sub





    Sub BindData(ByVal pCurrentPage As Integer)

        m_ocolAndyVideosObj = Nothing

        Dim intCount As Integer = 0

        intCount = clsBllFactory.oAndyVideosObjBLL.GetAndyVideosRecordCount()

        If intCount > 0 Then

            m_ocolAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideosByPage(intPageSize, pCurrentPage)

            AspNetPager1.CurrentPageIndex = pCurrentPage

            AspNetPager1.RecordCount = intCount

            radGrid1.DataSource = m_ocolAndyVideosObj

            radGrid1.DataBind()

        Else

            AspNetPager1.RecordCount = 0

            radGrid1.DataSource = New colAndyVideosObj

            radGrid1.DataBind()

        End If

    End Sub



    Private Sub Grid_Product_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles radGrid1.ItemDataBound

        Dim oclsAndyVideosObj As clsAndyVideosObj = Nothing

        Dim imgPic As System.Web.UI.WebControls.Image

        Dim btnPublish, btnCancelPublish As System.Web.UI.WebControls.Button





        If e.Item.ItemType = GridItemType.Item Or e.Item.ItemType = GridItemType.AlternatingItem Then

            imgPic = CType(e.Item.FindControl("imgPic"), System.Web.UI.WebControls.Image)

            btnPublish = CType(e.Item.FindControl("btnPublish"), System.Web.UI.WebControls.Button)

            btnCancelPublish = CType(e.Item.FindControl("btnCancelPublish"), System.Web.UI.WebControls.Button)



            oclsAndyVideosObj = e.Item.DataItem

            If oclsAndyVideosObj IsNot Nothing Then

                SetSmallImageUrl(imgPic, Server, oclsAndyVideosObj.Photo, AndyVideoPath, NoPicture, 66, 66)



                If oclsAndyVideosObj.IsPublish Then

                    btnCancelPublish.Visible = True

                    btnPublish.Visible = False

                Else

                    btnCancelPublish.Visible = False

                    btnPublish.Visible = True

                End If

            End If

        End If

    End Sub



    Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs) Handles RadAjaxManager1.AjaxRequest

        Dim strCommand As String = Nothing

        Dim strVideoID As String

        Dim oclsAndyVideosObj As clsAndyVideosObj

        Dim intPage, selectindex As Integer



        strCommand = e.Argument.Substring(0, e.Argument.IndexOf("#"))

        strVideoID = e.Argument.Split("#")(1)

        Select Case strCommand

            Case "New"

                BindData(1)

                AspNetPager1.CurrentPageIndex = 0

                radGrid1.MasterTableView.CurrentPageIndex = 0

                radGrid1.SelectedIndexes.Clear()

                radGrid1.SelectedIndexes.Add(0)

            Case "Edit"

                selectindex = radGrid1.SelectedIndexes(0)

                BindData(AspNetPager1.CurrentPageIndex())

                radGrid1.SelectedIndexes.Clear()

                radGrid1.SelectedIndexes.Add(selectindex)

            Case "Delete"

                Dim oFile As String = ""

                Dim oFile2 As String = ""



                Dim ocolAndyVideosObj As colAndyVideosObj

                ocolAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideosByPage(intPageSize, AspNetPager1.CurrentPageIndex)



                If radGrid1.SelectedItems.Count <= 0 Then

                    Return

                End If



                For Each draggedItem As GridDataItem In radGrid1.SelectedItems

                    strVideoID = draggedItem.GetDataKeyValue("VideoID")

                    oclsAndyVideosObj = ocolAndyVideosObj.Item(strVideoID)

                    If oclsAndyVideosObj IsNot Nothing Then

                        oclsAndyVideosObj.IsDelete = True

                        oclsAndyVideosObj.Dirty = True



                        oFile = Server.MapPath(AndyVideoPath + oclsAndyVideosObj.Photo)

                        oFile2 = Server.MapPath(SmallAndyVideoPath + oclsAndyVideosObj.Photo)

                    End If

                Next



                If clsBllFactory.oAndyVideosObjBLL.ModifyAndyVideos(ocolAndyVideosObj, Nothing) = 1 Then

                    BindData(1)

                    AspNetPager1.CurrentPageIndex = 0

                    radGrid1.MasterTableView.CurrentPageIndex = 0

                    radGrid1.SelectedIndexes.Clear()

                    radGrid1.SelectedIndexes.Add(0)



                    If oFile.Length > 0 AndAlso IO.File.Exists(oFile) Then

                        IO.File.Delete(oFile)

                    End If



                    If oFile2.Length > 0 AndAlso IO.File.Exists(oFile2) Then

                        IO.File.Delete(oFile2)

                    End If

                Else

                    Me.RadAjaxManager1.Alert("操作失敗,請刷新后再試!")

                End If

        End Select

    End Sub





    Protected Sub radGrid1_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles radGrid1.ItemCommand



        Try

            Dim strVideoID As String

            Dim oclsAndyVideosObj As clsAndyVideosObj





            If e.CommandName = "Publish" Then

                strVideoID = e.CommandArgument

                oclsAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideos(strVideoID, "")



                If oclsAndyVideosObj.IsPublish = True Then

                    Me.RadAjaxManager1.Alert("該視頻已經發佈。")

                    Exit Sub

                End If



                oclsAndyVideosObj.IsPublish = True

                oclsAndyVideosObj.Dirty = True



                If clsBllFactory.oAndyVideosObjBLL.UpdateAndyVideos(oclsAndyVideosObj, Nothing) = 1 Then

                    RefreshGrid()

                Else

                    Me.RadAjaxManager1.Alert("視頻發佈失敗。")

                End If

            ElseIf e.CommandName = "CancelPublish" Then

                strVideoID = e.CommandArgument

                oclsAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideos(strVideoID, "")



                If oclsAndyVideosObj.IsPublish = False Then

                    Me.RadAjaxManager1.Alert("該視頻已經取消發佈。")

                    Exit Sub

                End If



                oclsAndyVideosObj.IsPublish = False

                oclsAndyVideosObj.Dirty = True



                If clsBllFactory.oAndyVideosObjBLL.UpdateAndyVideos(oclsAndyVideosObj, Nothing) = 1 Then

                    RefreshGrid()

                Else

                    Me.RadAjaxManager1.Alert("視頻取消發佈失敗。")

                End If

            End If

        Catch ex As Exception

            Me.RadAjaxManager1.Alert("系統錯誤,請與我們聯繫。")

        End Try

    End Sub



    Private Sub RefreshGrid()

        Dim selectindex As Integer

        Try

            selectindex = radGrid1.SelectedIndexes(0)

            BindData(AspNetPager1.CurrentPageIndex())

            radGrid1.SelectedIndexes.Clear()

            radGrid1.SelectedIndexes.Add(selectindex)

        Catch ex As Exception

            BindData(AspNetPager1.CurrentPageIndex())

        End Try

    End Sub



End Class

Item Page

Html code : 

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="VideoItem.aspx.vb" Inherits="AwcWeb.VideoItem" %>



<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!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 id="Head1" runat="server">

    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />

    <title></title>

    <link href="css/Global.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="scripts/RadCommon.js"></script>

    <script type="text/javascript" src="scripts/ImageManger.js"></script>

    <script>

        function clear1() {

            document.getElementById("HfUrl").value = "";

            var img = document.getElementById("imgPhoto");

            img.src = "ImageManager/nophoto_s.jpg";

            img.style.width = "66px";

            img.style.height = "66px";



        }



             

    </script>

    <style>

        body

        {

            overflow: hidden;

        }

        #table2 tr td

        {

            text-align: left;

            height: 30px;

        }

        .alignRight

        {

            text-align: right !important;

        }

    </style>

</head>

<body>

    <form id="MyForm" runat="server">

    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

    </telerik:RadScriptManager>

    <div style="width: 700px; clear: both; text-align: center;">

        <table id="table2" border="0" cellpadding="0" cellspacing="0" style="border: 0; width: 700px;">

            <tr>

                <td style="width: 100px; height: 10px; text-align: right;">

                </td>

                <td style="width: 250px;">

                </td>

                <td style="width: 100px; text-align: right;">

                </td>

                <td style="width: 250px;">

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    生效日期:

                </td>

                <td>

                    <telerik:RadDatePicker ID="tpStartDate" runat="server" Skin="Default" Calendar-EnableShadows="true"

                        DateInput-DateFormat="yyyy-MM-dd" DateInput-EmptyMessage="請選生效日期" Width="220"

                        CssClass="inputCSS" />

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="tpStartDate"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

                <td class="alignRight">

                    圖片:

                </td>

                <td rowspan="4" style="height: 90px;">

                    <div id="izImgZoom1" class="ContentImg" style="overflow: hidden; width: 250px; height: 70px;

                        float: left;">

                        <table border="0" cellpadding="0" cellspacing="0" style="width: 66px; height: 66px;

                            float: left;">

                            <tr align="center" valign="middle">

                                <td align="center" valign="middle">

                                    <asp:Image ID="imgPhoto" runat="server" CssClass="imgSize" ImageUrl="ImageManager/nophoto_s.jpg" />

                                </td>

                            </tr>

                        </table>

                        <span style="line-height: 66px; margin-left: 5px; color: Red; font-size: 12px; float: left;">

                            建議圖片分辨率:308px * 154px </span>

                    </div>

                    <asp:HiddenField ID="HfUrl" runat="server" />

                    <div style="clear: both; width: 300px; height: 30px; overflow: hidden; padding-top: 10px;">

                        <telerik:RadUpload ID="RadUpload1" runat="server" ControlObjectsVisibility="ClearButtons"

                            Localization-Select="Browse" AllowedFileExtensions=".gif,.jpg,.bmp,.jpeg,.png"

                            InputSize="11" OverwriteExistingFiles="True" ReadOnlyFileInputs="True" MaxFileInputsCount="1"

                            Font-Overline="False" OnClientClearing="clear1">

                            <Localization Select="Browse" Clear="Clear" />

                        </telerik:RadUpload>

                    </div>

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    截止日期:

                </td>

                <td>

                    <telerik:RadDatePicker ID="tpExpireDate" runat="server" Skin="Default" Calendar-EnableShadows="true"

                        DateInput-DateFormat="yyyy-MM-dd" DateInput-EmptyMessage="請選截止日期" Width="220"

                        CssClass="inputCSS" />

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="tpExpireDate"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

                <td class="alignRight">

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    發佈日期:

                </td>

                <td>

                    <telerik:RadDatePicker ID="tpPublishDate" runat="server" Skin="Default" Calendar-EnableShadows="true"

                        DateInput-DateFormat="yyyy-MM-dd" DateInput-EmptyMessage="請選發佈日期" Width="220"

                        CssClass="inputCSS" />

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="tpPublishDate"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

                <td class="alignRight">

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    視頻類型:

                </td>

                <td>

                    <asp:DropDownList ID="ddlVideoType" runat="server" Width="100px">

                        <asp:ListItem Selected="True" Value="1">文件</asp:ListItem>

                        <asp:ListItem Value="2">視頻流</asp:ListItem>

                    </asp:DropDownList>

                </td>

                <td class="alignRight">

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    視頻連接:

                </td>

                <td colspan="3">

                    <asp:TextBox ID="txtVideo" runat="server" CssClass="inputCSS" Width="541px"></asp:TextBox>

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator8" runat="server" ControlToValidate="txtVideo"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    繁體標題:

                </td>

                <td>

                    <asp:TextBox ID="txtTitle_tc" runat="server" CssClass="inputCSS" Width="220px"></asp:TextBox>

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtTitle_tc"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

                <td class="alignRight">

                    簡體標題:

                </td>

                <td>

                    <asp:TextBox ID="txtTitle_sc" runat="server" CssClass="inputCSS" Width="220px"></asp:TextBox>

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtTitle_sc"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    英文標題:

                </td>

                <td>

                    <asp:TextBox ID="txtTitle_en" runat="server" CssClass="inputCSS" Width="220px"></asp:TextBox>

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server" ControlToValidate="txtTitle_en"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

                <td class="alignRight">

                    日語標題:

                </td>

                <td>

                    <asp:TextBox ID="txtTitle_jp" runat="server" CssClass="inputCSS" Width="220px"></asp:TextBox>

                    <span class="redCss">*</span>

                    <asp:RequiredFieldValidator ID="RequiredFieldValidator7" runat="server" ControlToValidate="txtTitle_jp"

                        Display="Dynamic" ErrorMessage="" ValidationGroup="SubmitGroup" ForeColor="Red" />

                </td>

            </tr>

            <tr>

                <td class="alignRight">

                    备注:

                </td>

                <td colspan="3">

                    <asp:TextBox ID="txtRemark" runat="server" CssClass="inputCSS" Width="541px"></asp:TextBox>

                </td>

            </tr>

            <tr>

                <td colspan="4" style="height: auto; padding-top: 20px; text-align: center">

                    <asp:Button ID="btnSure" Text="確定" CssClass="buttonStyle btnCss2" ValidationGroup="SubmitGroup"

                        runat="server" />    

                    <input type="button" id="btnCancel" class="buttonStyle btnCss2" value="取消" />

                </td>

            </tr>

        </table>

    </div>

    </form>

</body>

</html>

.net code:

Imports AWC.AndyVideosObj.AndyVideosObjEntry

Imports Telerik.Web.UI

Imports System.Drawing





Partial Public Class VideoItem

    Inherits System.Web.UI.Page



    Public Property VideoID() As String

        Get

            If ViewState("VideoID") Is Nothing Then

                Return String.Empty

            End If

            Return ViewState("VideoID").ToString()

        End Get

        Set(ByVal value As String)

            ViewState("VideoID") = value

        End Set

    End Property



    Public Property EditMode() As String

        Get

            If ViewState("EditMode") Is Nothing Then

                Return String.Empty

            End If

            Return ViewState("EditMode").ToString()

        End Get

        Set(ByVal value As String)

            ViewState("EditMode") = value

        End Set

    End Property



    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim oclsAndyVideosObj As clsAndyVideosObj

        If Session.Item("UserID") Is Nothing Then

            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", " CancelEdit();parent.window.location.href='Login.aspx';", True)

        End If



        If IsPostBack = False Then

            Dim strEditMode, strVideoID As String



            strEditMode = Request.QueryString("EditMode")

            If strEditMode IsNot Nothing Then

                EditMode = strEditMode

            Else

                Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('參數錯誤!'); CancelEdit();", True)

            End If



            If EditMode = "New" Then



            Else

                strVideoID = Request.QueryString("VideoID")

                If strVideoID IsNot Nothing Then

                    VideoID = strVideoID

                    oclsAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideos(VideoID, "")

                    If oclsAndyVideosObj IsNot Nothing Then

                        With oclsAndyVideosObj

                            txtTitle_tc.Text = .Title_tc

                            txtTitle_sc.Text = .Title_sc

                            txtTitle_en.Text = .Title_en

                            txtTitle_jp.Text = .Title_jp

                            tpStartDate.SelectedDate = .StartDate

                            tpExpireDate.SelectedDate = .ExpireDate

                            tpPublishDate.SelectedDate = .PublishDate

                            ddlVideoType.SelectedValue = .VideoType

                            txtVideo.Text = .Video

                            txtRemark.Text = .Remark



                            HfUrl.Value = .Photo

                            SetSmallImageUrl(imgPhoto, Server, .Photo, AndyVideoPath, NoPicture, 66, 66)



                        End With

                    End If

                Else

                    Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('參數錯誤!'); CancelEdit();", True)

                End If

            End If

        End If

    End Sub







    Private Sub btnSure_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSure.Click

        Dim strEditType As String = ""



        Dim oclsAndyVideosObj As clsAndyVideosObj

        Dim intResult As Integer



        If EditMode = "New" AndAlso tpStartDate.SelectedDate < Today Then

            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('生效日期不能小於今天!');", True)

            Exit Sub

        End If



        If tpExpireDate.SelectedDate < tpStartDate.SelectedDate Then

            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('截止日期不能小於生效日期!');", True)

            Exit Sub

        End If



        If tpPublishDate.SelectedDate < tpStartDate.SelectedDate Then

            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('發佈日期不能小於生效日期!');", True)

            Exit Sub

        End If



        If tpExpireDate.SelectedDate < tpPublishDate.SelectedDate Then

            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('發佈日期不能大於截止日期!');", True)

            Exit Sub

        End If





        Try

            Dim filename As String = ""

            Dim file As UploadedFile

            Dim oDirPath As String = ""

            Dim oSmallDirPath As String = ""

            Dim img As Drawing.Image = Nothing



            If Me.RadUpload1.UploadedFiles.Count <> 0 Then

                oDirPath = Server.MapPath(AndyVideoPath)

                If IO.Directory.Exists(oDirPath) = False Then

                    IO.Directory.CreateDirectory(oDirPath)

                End If



                oSmallDirPath = Server.MapPath(SmallAndyVideoPath)

                If IO.Directory.Exists(oSmallDirPath) = False Then

                    IO.Directory.CreateDirectory(oSmallDirPath)

                End If



                file = RadUpload1.UploadedFiles.Item(0)

                If Not [Object].Equals(file, Nothing) Then

                    Dim oImage As Drawing.Image = Drawing.Image.FromStream(file.InputStream)

                    If oImage IsNot Nothing Then

                        If oImage.Width > 2000 OrElse oImage.Height > 2000 Then

                            Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('您的圖片太大,圖片寬高不能超過2000px');", True)

                            Exit Sub

                        End If

                    End If



                    filename = Now.ToString("yyyyMMddHHmmssfff") + file.GetExtension

                    file.SaveAs(oDirPath + filename, True)





                    img = CType(Drawing.Image.FromStream(file.InputStream), Drawing.Image)

                    imageProc.MakeThumbnailPhoto(img, oSmallDirPath + filename, 308, 154)



                    HfUrl.Value = filename

                End If

            End If



            If EditMode = "New" Then

                VideoID = clsBllFactory.oAndyVideosObjBLL.GetObjectID()

                oclsAndyVideosObj = New clsAndyVideosObj(VideoID)

                oclsAndyVideosObj.IsPublish = False

                oclsAndyVideosObj.IsNew = True

            Else

                oclsAndyVideosObj = clsBllFactory.oAndyVideosObjBLL.GetAndyVideos(VideoID, "")

                If oclsAndyVideosObj Is Nothing Then

                    Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "alert('该商品目錄不存在或已被删除 !'); CancelEdit();", True)

                    Exit Sub

                End If

                oclsAndyVideosObj.Dirty = True

            End If



            With oclsAndyVideosObj

                .Title_tc = txtTitle_tc.Text

                .Title_sc = txtTitle_sc.Text

                .Title_en = txtTitle_en.Text

                .Title_jp = txtTitle_jp.Text

                .StartDate = tpStartDate.SelectedDate

                .ExpireDate = tpExpireDate.SelectedDate

                .PublishDate = tpPublishDate.SelectedDate

                .VideoType = ddlVideoType.SelectedValue

                .Video = txtVideo.Text

                .Remark = txtRemark.Text

                .Photo = HfUrl.Value

            End With



            If EditMode = "New" Then

                intResult = clsBllFactory.oAndyVideosObjBLL.InsertAndyVideos(oclsAndyVideosObj, Nothing)

                strEditType = "1"

            Else

                intResult = clsBllFactory.oAndyVideosObjBLL.UpdateAndyVideos(oclsAndyVideosObj, Nothing)

                strEditType = "2"

            End If



            If intResult = 1 Then

                Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "CloseAndRebind('succeed','" + strEditType + "');", True)

            Else

                Page.ClientScript.RegisterStartupScript(Me.GetType, "Message", "CloseAndRebind('fail','" + strEditType + "');", True)

            End If

        Catch ex As Exception



        End Try

    End Sub





End Class

JS Code:

// JScript File

function GetRadWindow() {

    var oWindow = null;

    if (window.radWindow) {

        oWindow = window.radWindow;

    }

    else if (window.frameElement.radWindow) {

        oWindow = window.frameElement.radWindow;

    }

    return oWindow;

}



function CancelEdit() {

    GetRadWindow().Close();

}



function CloseAndRebind(arg, RowIndex) {

    GetRadWindow().Close();

    GetRadWindow().BrowserWindow.refreshGrid(arg, RowIndex);

    return false;

}



function SessionClose() {

    GetRadWindow().Close();

    GetRadWindow().BrowserWindow.BackLogin();

    return false;

}



window.onload = function() {

    var btnCancel = document.getElementById("btnCancel");

    if (btnCancel != null) btnCancel.onclick = CancelEdit;

}



var LoadPageURL = ""

function OpenWindow(Purl, Ptitle, PwinWidth, PwinHeight, pWinName) {

    var oWindow = window.radopen(Purl + "&rdn=" + Math.random(), pWinName);

    oWindow.SetSize(PwinWidth, PwinHeight);

    oWindow.SetTitle(Ptitle);

    oWindow.set_modal(true);

    oWindow.Center();

    oWindow.add_close(OnWindowClientClose);

}



function OpenWin(Purl, Ptitle, PwinWidth, PwinHeight, pName) {

    var oWindow = window.radopen(Purl + "&rmd=" + Math.random(), pName);

    oWindow.SetSize(PwinWidth, PwinHeight);

    oWindow.SetTitle(Ptitle);

    oWindow.Center();

    oWindow.add_close(OnWindowClientClose);

}



function OnWindowClientClose(sender, eventArgs) {

    sender.SetUrl(LoadPageURL);

}



function AddLoadHandler(pFunc) {

    if (typeof (window.onload) != 'function')

        window.onload = pFunc;

    else {

        var oldFunc = window.onload;

        window.onload = function() {

            oldFunc();

            pFunc();

        }

    }

}



function BackLogin() {

    window.location = '';

}



function SessionEnd() {

    GetRadWindow().Close();

    GetRadWindow().BrowserWindow.GotoLogin();

    return false;

}





function AddClickHandler(btnID, addFunc) {

    var btnSure = document.getElementById(btnID);

    if (btnSure == null)

        return false;

    var oldFunc = btnSure.onclick;

    if (typeof oldFunc == 'function') {

        btnSure.onclick = function() {

            var result = oldFunc();

            for (var validator in Page_Validators) {



                var isValidated = Page_Validators[validator].style.display;

                if (isValidated == "inline" || isValidated == "") {

                    return false;

                }



            }

            return addFunc();



        }

    }

    else {

        btnSure.onclick = function() {

            return addFunc();

        };

    }

}



function PromptFunction() {

    return confirm("你确定要执行此项操作吗?");

}



//AddLoadHandler(function()

//{

//    AddClickHandler("btnSure",PromptFunction);

//});

  

你可能感兴趣的:(grid)