Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > .NET Framework > Forum > search ข้อมูล ค้นหาข้อมูลระหว่างวันที่และ ดรอปดาน์วลิส


 

[.NET] search ข้อมูล ค้นหาข้อมูลระหว่างวันที่และ ดรอปดาน์วลิส

 
Topic : 046611



โพสกระทู้ ( 2 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Blogger


ต้องการค้นหาข้อมูลระหว่างวันที่ โดยที่ถ้าวันที่ช่องใดช่องหนึ่งว่าง ให้ใส่วันที่ให้ครบก่อน แล้วดึงข้อมูลวันที่ต้องการค้นหามาโชว์ใน gridview ถ้าใส่วันที่ ดรอปดาวน์ก็ให้โชว์เงื่อนไขตามนั้น แต่ถ้าไม่ใส่อะไรเลยทั้ง 3 ช่องให้ดึงข้อมูลมาโชว์ทั้งหมด

อันนี้ลองทำแล้วเลือกวันที่ แค่วันเดียวได้แต่ว่าเลือกมากกว่า 1 วันมันจะได้ข้อมูลของรหัสมาแต่ว่าวันที่เป็นวันเดียวกันหมด ไม่รู้ว่าผิดตรงไหน
คือมีข้อมูล 2 วัน วันที่ 1 และวันที่ 2 ถ้าเลือกวันที่ 1 และวันที่ 2 ผล ปัจจุบันเป็นแบบนี้ง่ะ
1. 1111 1/8/2553 0:00:00 760.00 0
2. 1112 1/8/2553 0:00:00 760.00 0
3. 444444 1/8/2553 0:00:00 760.00 0
4. 5555 1/8/2553 0:00:00 760.00 0

วันที่เป็นวันที่ 1 หมดเยย



void ShowData()
{

string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where productsupplier.Id(+) = productsupplierdt.ProductSupplierId Group By ProductSupplierId";

string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
string enddate = Csql.Convert_dateCalendar(txtendDate.Text);



if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty) && (ddlProduct.SelectedValue != "--กรุณาเลือก--"))
{

dtP = Csql.SELECT_All("productsupplier where (DateBuy between '" + strdate + "'AND'" + enddate + "') AND SupplierId='" + ddlProduct.SelectedValue + "'");

}
else if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty))
{
dtP = Csql.SELECT_All("productsupplier WHERE DateBuy between '" + strdate + "'AND'" + enddate + "'");

}
else if ((txtStartDate.Text == string.Empty) && (txtendDate.Text == string.Empty))
{
dtP = Csql.SELECT_All("productsupplier");
}

else
{
string str = "<script language='javascript'>alert('กรุณาใส่ช่วงวันที่');window.focus ();</script>";
Page.RegisterStartupScript("onclick", str);

return;
}

if (dtP.Rows.Count > 0)
{

GV1.DataSource = dtP;
GV1.DataBind();
}
else
{
//DataTable dt = new DataTable();
//dt.Columns.Add(new DataColumn("Id", typeof(int)));
//DataRow dr = dt.NewRow();
//dt.Rows.Add(dr);
//GV1.DataSource = dt;
GV1.DataSource = null;
GV1.DataBind();
}
}

protected void GV1_RowCreated(object sender, GridViewRowEventArgs e )
{
string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
string enddate = Csql.Convert_dateCalendar(txtendDate.Text);

if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink data1 = (HyperLink)e.Row.FindControl("data1");
HyperLink data2 = (HyperLink)e.Row.FindControl("data2");
HyperLink data3 = (HyperLink)e.Row.FindControl("data3");
HyperLink data4 = (HyperLink)e.Row.FindControl("data4");



string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where (productsupplier.DateBuy between '" + strdate + "' AND '" + enddate + "') AND productsupplier.Id = productsupplierdt.ProductSupplierId Group By ProductSupplierId";


DataTable dt = Csql.ExecuteReader(sql);
//Response.Write(sql);
//Response.End();
if (dt.Rows.Count > 0)
{
data1.Text = dt.Rows[e.Row.DataItemIndex]["ReceiveCode"].ToString();
data1.NavigateUrl = "Buy.aspx?actions=Edit&uid=" + dt.Rows[e.Row.DataItemIndex]["SupplierId"].ToString();
data2.Text = dt.Rows[0]["DateBuy"].ToString();
data3.Text = dt.Rows[0]["TotalPrice"].ToString();
data4.Text = dt.Rows[0]["Status"].ToString();

}
}
runid = (e.Row.DataItemIndex + 1) + ".";
}



Tag : ASP

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-08-05 19:38:38 By : party View : 1376 Reply : 4
 

 

No. 1



โพสกระทู้ ( 108 )
บทความ ( 0 )



สถานะออฟไลน์


ขอเรียงก่อน เด๋วมาตอบค่ะ

Code (C#)
01.void ShowData()
02.{
03. 
04.string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where productsupplier.Id(+) = productsupplierdt.ProductSupplierId Group By ProductSupplierId";
05. 
06.string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
07.string enddate = Csql.Convert_dateCalendar(txtendDate.Text);
08. 
09. 
10. 
11.if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty) && (ddlProduct.SelectedValue != "--กรุณาเลือก--"))
12.{
13. 
14.dtP = Csql.SELECT_All("productsupplier where (DateBuy between '" + strdate + "'AND'" + enddate + "') AND SupplierId='" + ddlProduct.SelectedValue + "'");
15. 
16.}
17.else if ((txtStartDate.Text != string.Empty) && (txtendDate.Text != string.Empty))
18.{
19.dtP = Csql.SELECT_All("productsupplier WHERE DateBuy between '" + strdate + "'AND'" + enddate + "'");
20. 
21.}
22.else if ((txtStartDate.Text == string.Empty) && (txtendDate.Text == string.Empty))
23.{
24.dtP = Csql.SELECT_All("productsupplier");
25.}
26. 
27.else
28.{
29.string str = "<script language='javascript'>alert('กรุณาใส่ช่วงวันที่');window.focus ();</script>";
30.Page.RegisterStartupScript("onclick", str);
31. 
32.return;
33.}
34. 
35.if (dtP.Rows.Count > 0)
36.{
37. 
38.GV1.DataSource = dtP;
39.GV1.DataBind();
40.}
41.else
42.{
43.//DataTable dt = new DataTable();
44.//dt.Columns.Add(new DataColumn("Id", typeof(int)));
45.//DataRow dr = dt.NewRow();
46.//dt.Rows.Add(dr);
47.//GV1.DataSource = dt;
48.GV1.DataSource = null;
49.GV1.DataBind();
50.}
51.}
52. 
53.protected void GV1_RowCreated(object sender, GridViewRowEventArgs e )
54.{
55.string strdate = Csql.Convert_dateCalendar(txtStartDate.Text);
56.string enddate = Csql.Convert_dateCalendar(txtendDate.Text);
57. 
58.if (e.Row.RowType == DataControlRowType.DataRow)
59.{
60.HyperLink data1 = (HyperLink)e.Row.FindControl("data1");
61.HyperLink data2 = (HyperLink)e.Row.FindControl("data2");
62.HyperLink data3 = (HyperLink)e.Row.FindControl("data3");
63.HyperLink data4 = (HyperLink)e.Row.FindControl("data4");
64. 
65. 
66. 
67.string sql = "Select productsupplier.*,productsupplierdt.* From productsupplier,productsupplierdt where (productsupplier.DateBuy between '" + strdate + "' AND '" + enddate + "') AND productsupplier.Id = productsupplierdt.ProductSupplierId Group By ProductSupplierId";
68. 
69. 
70.DataTable dt = Csql.ExecuteReader(sql);
71.//Response.Write(sql);
72.//Response.End();
73.if (dt.Rows.Count > 0)
74.{
75.data1.Text = dt.Rows[e.Row.DataItemIndex]["ReceiveCode"].ToString();
76.data1.NavigateUrl = "Buy.aspx?actions=Edit&uid=" + dt.Rows[e.Row.DataItemIndex]["SupplierId"].ToString();
77.data2.Text = dt.Rows[0]["DateBuy"].ToString();
78.data3.Text = dt.Rows[0]["TotalPrice"].ToString();
79.data4.Text = dt.Rows[0]["Status"].ToString();
80. 
81.}
82.}
83.runid = (e.Row.DataItemIndex + 1) + ".";
84.}

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-05 23:16:00 By : njnight
 

 

No. 2



โพสกระทู้ ( 108 )
บทความ ( 0 )



สถานะออฟไลน์


Code (C#)
1.string strdate = Csql.Convert_dateCalendar(txtStartDate.Text + " 00:00:00");
2.string enddate = Csql.Convert_dateCalendar(txtendDate.Text + " 23:59:00");

ตอบถูกประเด็นหรือป่าวคะ ^_^
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-05 23:20:24 By : njnight
 

 

No. 3



โพสกระทู้ ( 108 )
บทความ ( 0 )



สถานะออฟไลน์


อันนี้ที่เราใช้อยู่อ่ะค่ะ เราไม่ค่อยใช้ Between เท่าใหร่
Code (C#)
1.string Qstr_select = " SELECT * FROM issue_table ";
2.              Qstr_select += " where ";
3.              if (txtStartDate.Text.Trim() != "" && txtEndDate.Text.Trim() != "")
4.              {
5.                  Qstr_select += " recorddate >='@Date_Begin' and recorddate <='@Date_End' ";
6.                  Qstr_select = Qstr_select.Replace("@Date_Begin", txtStartDate.Text + " 00:00:00");
7.                  Qstr_select = Qstr_select.Replace("@Date_End", txtEndDate.Text + " 23:59:00");
8.              }

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-05 23:23:04 By : njnight
 

 

No. 4



โพสกระทู้ ( 2 )
บทความ ( 0 )



สถานะออฟไลน์
Twitter Blogger

ขอบคุณทุก ๆ คำตอบคร้าบบบบทำได้แว้ว เย้ ๆ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2010-08-06 00:42:43 By : party
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : search ข้อมูล ค้นหาข้อมูลระหว่างวันที่และ ดรอปดาน์วลิส
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่