วันพุธที่ 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>

วันพฤหัสบดีที่ 24 ธันวาคม พ.ศ. 2558

เรียกข้อมูลจากฐานด้วย DataTable ผ่านObject คลาส

Imports System.Data.SqlClient
Public Class MyClassExecuteData
    Dim connectString As String = ConfigurationManager.ConnectionStrings.Item(("MyConnectionString")).ConnectionString

    Public Function GetDataTable(SQL As String) As DataTable
        Dim tag As New StringBuilder
        Dim query As String = SQL.ToString
        Dim t1 As New DataTable()
        Using conn As New SqlConnection(connectString)
            conn.Open()
            Dim cmd As New SqlCommand(query, conn)
            Using a As New SqlDataAdapter(cmd)
                a.Fill(t1)
            End Using
            conn.Close()
        End Using

        Return t1
    End Function

End Class


*************************** การใช้งาน *****************************************
Function getData(UserName As String) As Boolean

Dim obj As New MyClassExecuteData
Dim t1 As DataTable = obj.GetDataTable("SELECT * FROM register WHERE username = '" & UserName & "' ")

For Each row As DataRow In t1.Rows
     ltrregUserName.Text = row("regUserName").ToString
     txtPassword.Text = row("regPassword").ToString
     txtregFirstName.Text = row("regFirstName").ToString
     txtregLastName.Text = row("regLastName").ToString
Next


End Function

วันอาทิตย์ที่ 20 ธันวาคม พ.ศ. 2558

วันเสาร์ที่ 19 ธันวาคม พ.ศ. 2558

การแบ่งหน้าจาก Object ด้วย GridView แบบที่ 2

<asp:GridView ID="GridView22" runat="server"  AutoGenerateColumns="false" AllowPaging="True" AllowSorting="True" EnableViewState="true">
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                    <%# Eval("projectID")%>
            </ItemTemplate>           
        </asp:TemplateField>
    </Columns>
</asp:GridView>

****************************************************************************************

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            getFind(0)
        End If
End Sub

Sub getFind(PageIndex As Integer)
        Dim obj As New DataClassesABCDataContext
        GridView22.DataSource = obj.modFindData (1000)
        GridView22.PageIndex = PageIndex
        GridView22.DataBind()
End Sub

Private Sub GridView22_PageIndexChanging(sender As Object, e As GridViewPageEventArgs) Handles GridView22.PageIndexChanging
        getFind(e.NewPageIndex)

End Sub

วันอาทิตย์ที่ 13 ธันวาคม พ.ศ. 2558

การวนรอบ (Lopp) เอาข้อมูลจาก DataClasses โดย DataTable

        Dim obj As New DataClassesDataContext
        Dim dt As New DataTable
        Dim strDetail As New StringBuilder
        Dim result = obj.getCustomer_Profile_List("", "2")
        For Each p In result
            strDetail.Append(p.regUserName)

        Next

วันศุกร์ที่ 25 กันยายน พ.ศ. 2558

หาขนาดไฟล์ด้วย FileInfo



Dim fileSize As String

fileSize = New IO.FileInfo(Server.MapPath("/download/files/form_bantuek (1).doc")).Length

If fileSize >= 1048576 Then
   fileSize = FormatNumber((fileSize / 1024) / 1024, 2) & "MB."
ElseIf fileSize > 0 Then
   fileSize = FormatNumber(fileSize / 1024, 2) & "KB."

End If


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

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