 |
|
|
 |
 |
|
คนหาย ดันๆๆ
|
 |
 |
 |
 |
Date :
2013-05-16 00:54:15 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดันๆๆ
|
 |
 |
 |
 |
Date :
2013-05-16 08:34:30 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอดูโค๊ดหน่อยครับ เขียนอะไรไปแล้วบ้าง ขอดูทั้ง .aspx.vb และ .aspx ด้วยคับ
|
 |
 |
 |
 |
Date :
2013-05-16 08:56:44 |
By :
golfkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
DataReader ไม่ Support AllowPaging หรือเปล่าครับ
Code (VB.NET)
Dim objConn As New OleDbConnection
Dim objCmd As New OleDbCommand
Dim dtAdapter As New OleDbDataAdapter
Dim ds As New DataSet
Dim strConnString,strSQL As String
strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _
Server.MapPath("database/mydatabase.mdb")&";"
strSQL = "SELECT * FROM customer"
objConn.ConnectionString = strConnString
With objCmd
.Connection = objConn
.CommandText = strSQL
.CommandType = CommandType.Text
End With
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(ds)
'*** BindData to GridView ***'
myGridView.DataSource = ds
myGridView.DataBind()
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
|
 |
 |
 |
 |
Date :
2013-05-16 09:05:01 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขออภัยที่มาตอบช้าค่ะ ไม่ทราบว่าคนตอบยังอยู่ไหม อิอิ
โค้ด aspx ค่ะ
Code (ASP)
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="DataGrid1" %>
<%@ Register Assembly="eWorld.UI, Version=2.0.6.2393, Culture=neutral, PublicKeyToken=24d65337282035f2"
Namespace="eWorld.UI" TagPrefix="ew" %>
<!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>DataGrid & MySQL</title>
<style type="text/css">
#form1
{
width: 807px;
}
</style>
</head>
<body>
<form id="form1" runat="server" ><br />
<asp:DropDownList ID="MDropdown" runat="server">
<asp:ListItem Value="null">-- เดือน --</asp:ListItem>
<asp:ListItem Value="1">มกราคม</asp:ListItem>
<asp:ListItem Value="2">กุมภาพันธ์</asp:ListItem>
<asp:ListItem Value="3">มีนาคม</asp:ListItem>
<asp:ListItem Value="4">เมษายน</asp:ListItem>
<asp:ListItem Value="5">พฤษภาคม</asp:ListItem>
<asp:ListItem Value="6">กรกฏาคม</asp:ListItem>
<asp:ListItem Value="7">มิถุนายน</asp:ListItem>
<asp:ListItem Value="8">สิงหาคม</asp:ListItem>
<asp:ListItem Value="9">กันยายน</asp:ListItem>
<asp:ListItem Value="10">ตุลาคม</asp:ListItem>
<asp:ListItem Value="11">พฤศจิกายน</asp:ListItem>
<asp:ListItem Value="12">ธันวาคม</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="YDropDown" runat="server">
<asp:ListItem Value="null">-- ปี --</asp:ListItem>
<asp:ListItem Value = "2014">2557</asp:ListItem>
<asp:ListItem Value = "2013">2556</asp:ListItem>
<asp:ListItem Value = "2012">2555</asp:ListItem>
<asp:ListItem Value = "2011">2554</asp:ListItem>
<asp:ListItem Value ="2010">2553</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="ProDropDown" runat="server" Height="16px"
Width="134px">
<asp:ListItem Value="null">-- จังหวัด --</asp:ListItem>
<asp:ListItem Value="Yala">ยะลา</asp:ListItem>
<asp:ListItem Value="Pattanee">ปัตตานี</asp:ListItem>
<asp:ListItem Value="Nara">นราธิวาส</asp:ListItem>
<asp:ListItem Value="Songkhla">สงขลา</asp:ListItem>
<asp:ListItem Value="Satun">สตูล</asp:ListItem>
<asp:ListItem Value="Pattalung">พัทลุง</asp:ListItem>
<asp:ListItem Value="trang">ตรัง</asp:ListItem>
<asp:ListItem Value="Nakon">นครศรีธรรมราช</asp:ListItem>
<asp:ListItem Value="Krabee">กระบี่</asp:ListItem>
<asp:ListItem Value="Puket">ภูเก็ต</asp:ListItem>
<asp:ListItem Value="Pangkhla">พังงา</asp:ListItem>
<asp:ListItem Value="surat">สุราษฏานี</asp:ListItem>
<asp:ListItem Value="Chumpon">ชุมพร</asp:ListItem>
<asp:ListItem Value="Ranong">ระนอง</asp:ListItem>
</asp:DropDownList>
<asp:RadioButtonList ID="RadioList" runat="server"
Height="22px" RepeatDirection="Horizontal" RepeatLayout="Flow"
Width="134px" CellPadding="2" CellSpacing="2">
<asp:ListItem Value="Active">ติดตั้ง</asp:ListItem>
<asp:ListItem Value="Remove">รื้อถอน</asp:ListItem>
</asp:RadioButtonList>
<asp:Button ID="Button1" runat="server" Text="Search" />
<asp:Button ID="BtnAll" runat="server" Text="แสดงทั้งหมด" />
<asp:DataGrid id="myDataGrid" runat="server" AutoGenerateColumns="False"
ShowFooter="True" DataKeyField="ID" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
BorderWidth="1px" CellPadding="3" GridLines="Horizontal" PageSize="2"
OnPageIndexChanged="ShowPageCommand" >
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<SelectedItemStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C"
Mode="NumericPages" />
<AlternatingItemStyle BackColor="#F7F7F7" />
<ItemStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateColumn HeaderText="ลำดับที่" FooterStyle-Width = "100" >
<ItemTemplate>
<asp:Label id="lblID" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditID" Width = "50" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ID") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:Label ID="LableID" runat="server" Text="Id" ></asp:Label>
<asp:TextBox id="txtAddID" Width = "50" runat="server"></asp:TextBox>
</FooterTemplate>
<FooterStyle Width="100px"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="วันที่" FooterStyle-Width = "120" >
<ItemTemplate>
<asp:Label id="lblDate" runat="server" Text='<%# ctype(DataBinder.Eval(Container, "DataItem.Date"),datetime).tostring("dd/MM/yy") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<ew:CalendarPopup ID="CalendarPopup1" runat="server" TextBoxLabelStyle-Width = "80" ButtonStyle-Width = "10" ButtonStyle-Height = "10" > </ew:CalendarPopup>
</EditItemTemplate>
<FooterTemplate>
<ew:CalendarPopup ID="Cal_Pop" runat="server" ButtonStyle-Width = "10" ButtonStyle-Height = "10" TextBoxLabelStyle-Width = "80"> </ew:CalendarPopup>
</FooterTemplate>
<FooterStyle Width="120px"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="ติดตั้ง" HeaderStyle-Width = "100" >
<ItemTemplate>
<asp:Label id="lblActive" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Active") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditActive" size="15" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Active") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButton ID="RadioBtn1" runat="server" Text = "ติดตั้ง" />
</FooterTemplate>
<HeaderStyle Width="100px"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="รื้อถอน" HeaderStyle-Width = "100" FooterStyle-Width = "" >
<ItemTemplate>
<asp:Label id="lblRemove" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Remove") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditRemove" size="15" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Remove") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:RadioButton ID="RadioBtn2" runat="server" Text = "รื้อถอน" Checked="False" />
</FooterTemplate>
<HeaderStyle Width="100px"></HeaderStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="จังหวัด" FooterStyle-Width = "100" >
<ItemTemplate>
<asp:Label id="lblProvince" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Province") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="txtEditProvince" runat="server" >
<asp:ListItem Value="null">-- จังหวัด --</asp:ListItem>
<asp:ListItem Value="Yala">ยะลา</asp:ListItem>
<asp:ListItem Value="Pattanee">ปัตตานี</asp:ListItem>
<asp:ListItem Value="Nara">นราธิวาส</asp:ListItem>
<asp:ListItem Value="Songkhla">สงขลา</asp:ListItem>
<asp:ListItem Value="Satun">สตูล</asp:ListItem>
<asp:ListItem Value="Pattalung">พัทลุง</asp:ListItem>
<asp:ListItem Value="trang">ตรัง</asp:ListItem>
<asp:ListItem Value="Nakon">นครศรีธรรมราช</asp:ListItem>
<asp:ListItem Value="Krabee">กระบี่</asp:ListItem>
<asp:ListItem Value="Puket">ภูเก็ต</asp:ListItem>
<asp:ListItem Value="Pangkhla">พังงา</asp:ListItem>
<asp:ListItem Value="surat">สุราษฏานี</asp:ListItem>
<asp:ListItem Value="Chumpon">ชุมพร</asp:ListItem>
<asp:ListItem Value="Ranong">ระนอง</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="txtAddProvince" runat="server" >
<asp:ListItem Value="null">-- จังหวัด --</asp:ListItem>
<asp:ListItem Value="Yala">ยะลา</asp:ListItem>
<asp:ListItem Value="Pattanee">ปัตตานี</asp:ListItem>
<asp:ListItem Value="Nara">นราธิวาส</asp:ListItem>
<asp:ListItem Value="Songkhla">สงขลา</asp:ListItem>
<asp:ListItem Value="Satun">สตูล</asp:ListItem>
<asp:ListItem Value="Pattalung">พัทลุง</asp:ListItem>
<asp:ListItem Value="trang">ตรัง</asp:ListItem>
<asp:ListItem Value="Nakon">นครศรีธรรมราช</asp:ListItem>
<asp:ListItem Value="Krabee">กระบี่</asp:ListItem>
<asp:ListItem Value="Puket">ภูเก็ต</asp:ListItem>
<asp:ListItem Value="Pangkhla">พังงา</asp:ListItem>
<asp:ListItem Value="surat">สุราษฏานี</asp:ListItem>
<asp:ListItem Value="Chumpon">ชุมพร</asp:ListItem>
<asp:ListItem Value="Ranong">ระนอง</asp:ListItem>
</asp:DropDownList>
</FooterTemplate>
<FooterStyle Width="100px"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="จำนวน" FooterStyle-Width = "100" >
<ItemTemplate>
<asp:Label id="lblNum" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Num") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditNum" size="5" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Num") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddNum" size="2" runat="server"></asp:TextBox>
<asp:Button id="btnAdd" runat="server" Text="Add" CommandName="Add"></asp:Button>
</FooterTemplate>
<FooterStyle Width="100px"></FooterStyle>
</asp:TemplateColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="Edit" HeaderText="Modify" >
</asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete" HeaderText="Delete"></asp:ButtonColumn>
</Columns>
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
</asp:DataGrid>
<p>
<asp:Label ID="Lb1" runat="server" Text="Label"></asp:Label>
</p>
</form>
</body>
</html>
โค้ด aspx.vb ค่ะ
Code (VB.NET)
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.DateTime
Imports eWorld.UI
Imports System.Data.SqlClient
Partial Class DataGrid1
Inherits System.Web.UI.Page
Dim objConn As MySqlConnection
Dim objCmd As MySqlCommand
Dim strSQL As String
Dim Maxid As Integer
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim strConnString As String
strConnString = "Server=localhost;User Id=root; Password=; Database=reportstate; Pooling=false; Convert Zero Datetime=True;"
objConn = New MySqlConnection(strConnString)
objConn.Open()
If Not Page.IsPostBack() Then
BindData()
End If
End Sub
Protected Sub BindData()
Dim Data As New DataSet
Dim dtReader As MySqlDataReader
strSQL = "SELECT * FROM tbl_infomation "
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to DataGrid ***'
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Sub ShowPageCommand(ByVal sender As Object, ByVal e As DataGridPageChangedEventArgs)
myDataGrid.CurrentPageIndex = e.NewPageIndex
BindData()
End Sub
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
objConn.Close()
objConn = Nothing
End Sub
Protected Sub myDataGrid_CancelCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles myDataGrid.CancelCommand
myDataGrid.EditItemIndex = -1
myDataGrid.ShowFooter = True
BindData()
End Sub
Protected Sub myDataGrid_DeleteCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles myDataGrid.DeleteCommand
strSQL = "DELETE FROM tbl_infomation WHERE ID = '" & myDataGrid.DataKeys.Item(e.Item.ItemIndex) & "'"
objCmd = New MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
myDataGrid.EditItemIndex = -1
BindData()
End Sub
Protected Sub myDataGrid_EditCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles myDataGrid.EditCommand
myDataGrid.EditItemIndex = e.Item.ItemIndex
myDataGrid.ShowFooter = False
BindData()
End Sub
Protected Sub myDataGrid_ItemCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles myDataGrid.ItemCommand
If e.CommandName = "Add" Then
'*** ID ***'
Dim txtID As TextBox = CType(e.Item.FindControl("txtAddID"), TextBox)
Dim Lid As Label = CType(e.Item.FindControl("LableID"), Label)
Dim objCmd As MySqlCommand
Dim strSQL As String
Dim da As New MySqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
strSQL = "select Max(ID) As Maxid from tbl_infomation"
objCmd = New MySqlCommand(strSQL, objConn)
da.SelectCommand = objCmd
da.Fill(ds, "tbl_infomation") 'Keep data to Dataset
Maxid = CInt(ds.Tables("tbl_infomation").Rows(0)("Maxid").ToString()) + 1
Lid.Text = Maxid
'*** Date ***'
Dim txtDate As CalendarPopup = DirectCast(e.Item.FindControl("Cal_Pop"), CalendarPopup)
Dim day1 As Date = txtDate.SelectedDate
Dim Day_1 As Date = day1.Year & "-" & day1.ToString("MM-dd")
'*** Active ***'
Dim CheckActive As RadioButton = CType(e.Item.FindControl("RadioBtn1"), RadioButton)
Dim ChAc As String = CheckActive.Checked
'*** Remove ***'
Dim CheckRemove As RadioButton = CType(e.Item.FindControl("RadioBtn2"), RadioButton)
Dim ChRe As String = CheckRemove.Checked
'*** Province ***'
Dim txtProvince As DropDownList = CType(e.Item.FindControl("txtAddProvince"), DropDownList)
Dim txt_Province As String = txtProvince.SelectedValue
'*** Num ***'
Dim txtNum As TextBox = CType(e.Item.FindControl("txtAddNum"), TextBox)
If ChAc = True Then
strSQL = "INSERT INTO tbl_infomation (ID,Date,Active,Province,Num)VALUES('" & txtID.Text & "','" & day1.Year & "-" & day1.ToString("MM-dd") & "','Yes' ,'" & txt_Province & "','" & txtNum.Text & "')"
ElseIf ChRe = True Then
strSQL = "INSERT INTO tbl_infomation (ID,Date,Remove,Province,Num)VALUES('" & txtID.Text & "','" & day1.Year & "-" & day1.ToString("MM-dd") & "','Yes' ,'" & txt_Province & "','" & txtNum.Text & "')"
End If
objCmd = New MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
BindData()
End If
End Sub
Protected Sub myDataGrid_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles myDataGrid.UpdateCommand
'*** ID ***'
Dim txtID As TextBox = CType(e.Item.FindControl("txtEditID"), TextBox)
'*** Date ***'
Dim txt_Date As CalendarPopup = DirectCast(e.Item.FindControl("CalendarPopup1"), CalendarPopup)
Dim day1 As Date = txt_Date.SelectedDate
'*** Active ***'
Dim txtActive As TextBox = CType(e.Item.FindControl("txtEditActive"), TextBox)
'*** Remove ***'
Dim txtRemove As TextBox = CType(e.Item.FindControl("txtEditRemove"), TextBox)
'*** Province ***'
Dim txtProvince As DropDownList = CType(e.Item.FindControl("txtEditProvince"), DropDownList)
Dim txt_Province As String = txtProvince.SelectedValue
'*** Num ***'
Dim txtNum As TextBox = CType(e.Item.FindControl("txtEditNum"), TextBox)
strSQL = "UPDATE tbl_infomation SET ID = '" & txtID.Text & "' " & _
" ,Date = '" & day1.Year & "-" & day1.ToString("MM-dd") & "' " & _
" ,Active = '" & txtActive.Text & "' " & _
" ,Remove = '" & txtRemove.Text & "' " & _
" ,Province = '" & txt_Province & "' " & _
" ,Num = '" & txtNum.Text & "' " & _
" WHERE ID = '" & myDataGrid.DataKeys.Item(e.Item.ItemIndex) & "'"
objCmd = New MySqlCommand(strSQL, objConn)
objCmd.ExecuteNonQuery()
myDataGrid.EditItemIndex = -1
myDataGrid.ShowFooter = True
BindData()
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MStr As String = MDropdown.SelectedValue
Dim YStr As String = YDropDown.SelectedValue
Dim PStr As String = ProDropDown.SelectedValue
Dim Rbtn As String = RadioList.SelectedValue
If (Rbtn = "Active") And (PStr <> "null") Or (YStr <> "null") Or (MStr <> "null") Then
If (PStr = "null") And (YStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Month(Date) = '" & MStr & "' and Active = 'Yes' "
ElseIf (PStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Active = 'Yes' "
ElseIf (YStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Active = 'Yes' "
ElseIf MStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Year(Date) = '" & YStr & "' and Active = 'Yes'"
ElseIf YStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Month(Date) = '" & MStr & "' and Active = 'Yes' "
ElseIf PStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' and Active = 'Yes' "
Else
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' and Province = '" & PStr & "' and Active = 'Yes'"
End If
ElseIf (Rbtn = "Remove") And (PStr <> "null") Or (YStr <> "null") Or (MStr <> "null") Then
If (PStr = "null") And (YStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Month(Date) = '" & MStr & "' and Remove = 'Yes'"
ElseIf (PStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Remove = 'Yes' "
ElseIf (YStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Remove = 'Yes' "
ElseIf MStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Year(Date) = '" & YStr & "' and Remove = 'Yes' "
ElseIf YStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Month(Date) = '" & MStr & "' and Remove = 'Yes'"
ElseIf PStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' and Remove = 'Yes' "
Else
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' and Province = '" & PStr & "' and Remove = 'Yes' "
End If
ElseIf (Rbtn = "Active") And (PStr = "null") And (YStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Active = 'Yes' "
ElseIf (Rbtn = "Remove") And (PStr = "null") And (YStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Remove = 'Yes' "
Else
If (PStr = "null") And (YStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Month(Date) = '" & MStr & "' "
ElseIf (PStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' "
ElseIf (YStr = "null") And (MStr = "null") Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' "
ElseIf MStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Year(Date) = '" & YStr & "' "
ElseIf YStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Province = '" & PStr & "' and Month(Date) = '" & MStr & "' "
ElseIf PStr = "null" Then
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' "
Else
strSQL = "SELECT * FROM tbl_infomation where Year(Date) = '" & YStr & "' and Month(Date) = '" & MStr & "' and Province = '" & PStr & "' "
End If
End If
Dim dtReader As MySqlDataReader
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to DataGrid ***'
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Protected Sub BtnAll_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnAll.Click
strSQL = "SELECT * FROM tbl_infomation "
Dim dtReader As MySqlDataReader
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
'*** BindData to DataGrid ***'
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()
dtReader.Close()
dtReader = Nothing
End Sub
Protected Sub myDataGrid_pageIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles myDataGrid.PageIndexChanged
End Sub
End Class
|
 |
 |
 |
 |
Date :
2013-05-16 17:36:09 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ps มือใหม่ ลอกเขามาเยอะเหมือนกันค่ะ แหะๆ
|
 |
 |
 |
 |
Date :
2013-05-16 17:37:04 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ps ตอนนี้แก้ไปแก้มา โค้ด error อ่ะค่ะ ช่วยดู ให้หน่อย T^T
|
 |
 |
 |
 |
Date :
2013-05-16 17:50:28 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลองปรับดูครับ
<asp:DataGrid id="myDataGrid" runat="server" AllowPaging="True" AutoGenerateColumns="False"
ShowFooter="True" DataKeyField="ID" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None"
BorderWidth="1px" CellPadding="3" GridLines="Horizontal" PageSize="2"
OnPageIndexChanged="ShowPageCommand_PageIndexChanging" >
แล้วลองคิวรี่ใหม่อีกครับครับ
Code (VB.NET)
Protected Sub ShowPageCommand_PageIndexChanging(sender As Object, e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles ShowPageCommand_PageIndexChanging
myDataGrid.PageIndex = e.NewPageIndex
xxxx
strSQL = "SELECT * FROM tbl_infomation "
objCmd = New MySqlCommand(strSQL, objConn)
dtReader = objCmd.ExecuteReader()
myDataGrid.DataSource = dtReader
myDataGrid.DataBind()
xxx
End Sub
|
 |
 |
 |
 |
Date :
2013-05-17 10:55:59 |
By :
golfkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ยังไม่ได้ค่ะ ต้องมี ประกาศ ตัวแปร อะไรมากกว่านี้ไหมคะ
|
 |
 |
 |
 |
Date :
2013-05-17 13:16:41 |
By :
saw series |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ฟ้อง Error ว่าอะไรคับ
|
 |
 |
 |
 |
Date :
2013-05-17 13:28:10 |
By :
golfkub |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|