วันเสาร์ที่ 9 กรกฎาคม พ.ศ. 2559

การเรียกข้อมูลในฟังก์ชั่น จากไฟล์ ashx เพื่อนำค่าไปใช้ หรือ แสดงบน javascript


<script type="text/javascript">

    function getData_ashx() {
        var response = '';
        $.ajax({
            type: "GET",
            url: "/class/ashx/GraphHandler.ashx",
            async: false,
            success: function (text) {
                response = text;
            }
        });
        alert(response);
                     return response;
    }
</script>


*********  GraphHandler.ashx  **********************
Imports System.Web
Imports System.Web.Services

Public Class GraphHandler
    Implements System.Web.IHttpHandler

    Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest

        context.Response.ContentType = "text/plain"
        context.Response.Write(getdata_Chart())

    End Sub

    Public Shared Function getdata_Chart() As String
        Dim str As New StringBuilder

        str.Append("{ y: '2006', a: 50, b: 90, c: 112 },")
        str.Append("{ y: '2007', a: 75, b: 65, c: 95 },")
        str.Append("{ y: '2008', a: 50, b: 40, c: 80 },")
        str.Append("{ y: '2009', a: 75, b: 65, c: 96 },")
        str.Append("{ y: '2010', a: 50, b: 40, c: 75 },")
        str.Append("{ y: '2011', a: 75, b: 65, c: 110 },")
        str.Append("{ y: '2012', a: 100, b: 90, c: 132 },")
        str.Append("{ y: '2013', a: 125, b: 110, c: 152 },")
        str.Append("{ y: '2014', a: 145, b: 135, c: 165 }")

        Return str.ToString
    End Function


    ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
        Get
            Return False
        End Get
    End Property

End Class

วันอังคารที่ 31 พฤษภาคม พ.ศ. 2559

Redirect ไปยังหน้าเพจอื่นโดยใช้ TextBox Search โดยการ Enter

จากโค้ดเป็นการสั่งให้ Redirect ไปยังหน้าเพจค้นหา โดยรับค่าจาก TextBox Search เมื่อพิมพ์ข้อความแล้ว ต้องกด ปุ่ม Enter ที่แป้นคีย์บอร์ด จากนั้นคำค้นจะถูกส่งผ่าน URL เพื่อทำการค้นหาในหน้าเพจที่เราต้องการ


form onkeypress ="javascript:return  searchActive(event);" >
    <div class="form-group">
        <input type="text" id="top_search" name="top-search" runat ="server" >
    </div>
</form>

<script type="text/javascript">
    function searchActive(evt) {
        var charCode = (evt.which) ? evt.which : event.keyCode;
        if (charCode == 13) {
            window.location.replace("/?search=" + document.getElementById('<%=top_search.ClientID%>').value);
            return false;
        }
    }

</script>

วันเสาร์ที่ 21 พฤษภาคม พ.ศ. 2559

ฟังก์ชั่นในการปัดเศษ Math.Ceiling

หากต้องการปัดเศษ เพื่อการคำนวณหรือแสดงผล เช่นในตัวอย่างเป็น โปรเจค บทเรียนออนไลน์ที่ผู้สอนสามารถกำหนดร้อยละในการผ่านเกณฑ์ (ในภาพคือ 75%) ซึ่งผลเรียนจะต้องผ่าน 7.5 ข้อขึ้นไป แต่หากข้อสอบมีการนับเป็นจำนวนเต็ม ซึ่งต้องแสดงผล คือ 8 ข้อ เราสามารถเขียนชุดคำสั่ง ดังตัวอย่างนี้

----------------------- VB.NET SourceCode----------------------------

Dim num As Double = Math.Ceiling((10 * 75) / 100)

------------------------------------------------------------
Dim press As Integer = Math.Ceiling((Repeater1.Items.Count - 1) * Val(hdd_Present.Value) / 100)
------------------------------------------------------------


วันอังคารที่ 17 พฤษภาคม พ.ศ. 2559

ตารางซ้อนตาราง (Repeater in Repeater) ASP.NET & VB.NET

*********************  ASP.NET Code ***********************
<
asp:Repeater ID="ParentRepeater" runat="server">
    <ItemTemplate>
        <!-- Repeated data -->
        <asp:Repeater ID="ChildRepeater" runat="server">
            <ItemTemplate>
                <!-- Nested repeated data -->
            </ItemTemplate>
        </asp:Repeater>
    </ItemTemplate>
</asp:Repeater>
*********************  VB.NET Code ***********************
Private Sub ParentRepeater_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles ParentRepeater.ItemDataBound
Dim ChildRepeater As Repeater = e.Item.FindControl("ChildRepeater")

Dim SQL As String
       SQL = "SELECT………FROM ………"

       ChildRepeater.DataSource = objMyClassExecuteData.GetDataTable(SQL)
       ChildRepeater.DataBind()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim SQL As String
    SQL = "SELECT………FROM ………"
    ParentRepeater.DataSource = objMyClassExecuteData.GetDataTable(SQL)
    ParentRepeater.DataBind()
End
Sub


อ้างอิง:http://stackoverflow.com/questions/2923137/repeater-in-repeater

วันพุธที่ 4 พฤษภาคม พ.ศ. 2559

คำสั่ง เลือกทั้งหมด โดยใช้ CheckBox แสดงผลรายการข้อมูลด้วย Repeater


<
asp:Repeater id="myRepeater" runat="server"  >
       <HeaderTemplate>
              <table  class ="table  table-bordered">
                     <tr>
                <th>
                   <input id="chkAll" onclick="javascript: SelectAllCheckboxes(this);"
                   runat="server" type="checkbox"  /> <b style="color :red"> เลือกทั้งหมด</b>
                </th>

                     </tr>
       </HeaderTemplate>
       <ItemTemplate>
              <tr>
            <td>
                <asp:CheckBox ID="chkSelect" runat="server"  /> <%# Eval("student_Fullname")%>
            </td>
              </tr>              
       </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
       </asp:Repeater>

<script language="javascript">
    function SelectAllCheckboxes(spanChk) {
        // Added as ASPX uses SPAN for checkbox
        var oItem = spanChk.children;
        var theBox = (spanChk.type == "checkbox") ?
            spanChk : spanChk.children.item[0];
        xState = theBox.checked;
        elm = theBox.form.elements;

        for (i = 0; i < elm.length; i++)
            if (elm[i].type == "checkbox" &&
                     elm[i].id != theBox.id) {
                //elm[i].click();
                if (elm[i].checked != xState)
                    elm[i].click();
                //elm[i].checked=xState;
            }
    }

</script>

********************** Source Code **************************************

Function SaveData() As Boolean
 With myRepeater
  Dim i As Integer
  Dim sql, sqlScore As New StringBuilder
  Dim score As Integer

   For i = 0 To .Items.Count - 1
    Dim chkSelect As CheckBox = CType(.Items(i).FindControl("chkSelect"), CheckBox)
   Next

 End With
End Function

วันจันทร์ที่ 4 มกราคม พ.ศ. 2559

ทำตัวหนังสือวิ่งด้วย marquee

<div class="container">
<div class="row hidden-xs"  style="border-bottom :solid 1px #e8e8ec">
<div class="col-md-10 col-md-offset-1 site-block"  >
<marquee behavior="alternate" scrollamount="2">
     <a href="javascript:void(0)" >
<strong class =" text-danger menumain" style="font-size:20px;"> การ  สวัสดีปีใหม่ 2016 </strong>
     </a>
</marquee>

</div></div></div>

การใช้ WebClient สำหรับเรียก URL

Dim _url As String = " https :// www . MyDomain . com /?q=ทดสอบ " Dim wc As New System . Net . WebClient () wc . Encodin...