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 > โชว์ข้อมูลที่ค้นหาจากหลายตาราง ... ต้องการที่จะแสดงข้อมูลที่ค้นหา....ซึ่งข้อมูลมาจากหลายตารางเป็นดรอปดาวน์ลิสต์ให้ค้นห


 

[.NET] โชว์ข้อมูลที่ค้นหาจากหลายตาราง ... ต้องการที่จะแสดงข้อมูลที่ค้นหา....ซึ่งข้อมูลมาจากหลายตารางเป็นดรอปดาวน์ลิสต์ให้ค้นห

 
Topic : 037377



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



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


ต้องการที่จะแสดงข้อมูลที่ค้นหา....ซึ่งข้อมูลมาจากหลายตารางเป็นดรอปดาวน์ลิสต์ให้ค้นหา....แต่จะแสดงข้อมูลแค่ครั้งละตาราง....ต้องการที่จะให้แสดงในDatalistอันเดียวกัน ไม่ทราบว่าต้องทำยังไง...วานช่วยหน่อยค่ะ



Tag : - - - -

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2010-01-20 16:35:14 By : sunshinesnow View : 1865 Reply : 6
 

 

No. 1



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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


ใช้ event selectedindexchange ของ dropdownlist ให้ไปรันคำสั่ง

ให้เอาค่าที่เลือกใน dorpdownlist ไปเลือก sql command ให้ไป query ข้อมูลใน table
Date : 2010-01-20 17:01:01 By : tungman
 

 

No. 2



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



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

งง ค่ะ...ช่วยยกตัวอย่างพร้อมอธิบายได้มั๊ยค่ะ
Date : 2010-01-20 17:06:04 By : sunshinesnow
 

 

No. 3



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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


SelectSqlCommand.aspx
01.<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectSqlCommand.aspx.cs" Inherits="SelectSqlCommand" %>
02. 
03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04. 
06.<head runat="server">
07.    <title>Untitled Page</title>
08.</head>
09.<body>
10.    <form id="form1" runat="server">
11.    <div>
12.        <asp:DropDownList ID="DropDownList1" runat="server">
13.        </asp:DropDownList>
14.        <asp:DataList ID="DataList1" runat="server">
15.            <ItemTemplate>
16.                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
17.                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
18.            </ItemTemplate>
19.        </asp:DataList>
20.    </div>
21.    </form>
22.</body>
23.</html>

SelectSqlCommand.aspx.cs
01.using System;
02.using System.Collections;
03.using System.Configuration;
04.using System.Data;
05.using System.Linq;
06.using System.Web;
07.using System.Web.Security;
08.using System.Web.UI;
09.using System.Web.UI.HtmlControls;
10.using System.Web.UI.WebControls;
11.using System.Web.UI.WebControls.WebParts;
12.using System.Xml.Linq;
13. 
14.using System.Data.SqlClient;
15.using System.Web.Configuration;
16. 
17.public partial class SelectSqlCommand : System.Web.UI.Page
18.{
19.    private string sqlCommandString;
20.    private string TableID;
21.    private string TableData;
22. 
23.    protected void Page_Load(object sender, EventArgs e)
24.    {
25.        sqlCommandString = "Select * From [TableDay]"; //กำหนดค่า initial ให้ sqlCommandString
26.        TableID = "DayID"; //มันคือชื่อฟิลด์
27.        TableData = "DayName"; //มันคือชื่อฟิลด์
28. 
29.        if (!IsPostBack)
30.        {
31.            //ป้อน ListItem ให้ DropDownList1
32.            DropDownList1.Items.Add(new ListItem("ตารางวัน", "Day"));
33.            DropDownList1.Items.Add(new ListItem("ตารางเดือน", "Month"));
34. 
35.            DropDownList1.Items[0].Selected = true;
36.        }
37. 
38.        DropDownList1.AutoPostBack = true;
39.        DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
40. 
41.        DataList1.ItemDataBound += new DataListItemEventHandler(DataList1_ItemDataBound);
42. 
43.        BindData();
44.    }
45. 
46.    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
47.    {
48.        switch (DropDownList1.SelectedItem.Value)
49.        {
50.            case "Day":
51.                sqlCommandString = "Select * From [TableDay]";
52.                TableID = "DayID"; //มันคือชื่อฟิลด์
53.                TableData = "DayName"; //มันคือชื่อฟิลด์
54.                break;
55.            case "Month":
56.                sqlCommandString = "Select * From [TableMonth]";
57.                TableID = "MonthID"; //มันคือชื่อฟิลด์
58.                TableData = "MonthName"; //มันคือชื่อฟิลด์
59.                break;
60.        }
61. 
62.        BindData();
63.    }
64. 
65.    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
66.    {
67.        Label LabelBind1 = (Label)(e.Item.FindControl("Label1"));
68.        Label LabelBind2 = (Label)(e.Item.FindControl("Label2"));
69. 
70.        if (LabelBind1 != null)
71.            LabelBind1.Text = DataBinder.Eval(e.Item.DataItem, TableID).ToString();
72. 
73.        if (LabelBind2 != null)
74.            LabelBind2.Text = DataBinder.Eval(e.Item.DataItem, TableData).ToString();
75.    }
76. 
77.    private void BindData()
78.    {
79.        string sqlConnectionString = WebConfigurationManager.ConnectionStrings["SqlConnectionString"].ToString();
80.        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);
81. 
82.        SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
83.        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);
84. 
85.        DataTable Dt = new DataTable();
86.        sqlDataAdapter.Fill(Dt);
87. 
88.        DataList1.DataSource = Dt;
89.        DataList1.DataBind();
90.    }
91.}

Date : 2010-01-20 19:28:53 By : tungman
 

 

No. 4



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



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

ขอเป็นภาษา vb.netได้ไหมค่ะ...ยัง งงอยู่เลย...
เช่น มีข้อมูลอยู่ในตาราง A,B,C ซึ่งระหว่างตารางไม่ได้สัมพันธ์กันค่ะ...แค่เอารหัสจากตาราง D มาเป็นFK เท่านั้น..
สงสัยว่า..เราจะใช้ฟอร์ม Gridview ฟอร์มเดียวได้หรือป่าวค่ะ ในการแสดงข้อมูล..แล้วเราจะเขียนส่วนของการแสดงข้อมูลยังไงค่ะ เพราะเคยใช้แต่แบบแสดงข้อมูลจาก2ตารางที่สัมพันธ์กันเช่นจากตาราง AกับDเอามาjoinกันแล้วแสดง..แต่เหมือนเราค้นหาจากตารางAข้อมูลเป็นแบบนึง ตารางBและCเป็นแบบนึง....ชื่อฟิลด์แต่ละฟิลด์ก็ไม่เหมือนกันแล้ว...ก็เลยงงว่าเวลาที่เราค้นหาแล้วข้อมูลมันจะแสดงออกมายังไง
Date : 2010-01-21 20:58:29 By : sunshinesnow
 

 

No. 5



โพสกระทู้ ( 3,144 )
บทความ ( 1 )

สมาชิกที่ใส่เสื้อไทยครีเอท

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


วันนี้ เหนื่อยจริงๆ ไว้พรุ่งนี้มาบอกที่เหลือนะ

SelectSqlCommandVB.aspx
01.<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SelectSqlCommandVB.aspx.vb" Inherits="SelectSqlCommandVB" %>
02. 
03.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
04. 
06.<head runat="server">
07.    <title>Untitled Page</title>
08.</head>
09.<body>
10.    <form id="form1" runat="server">
11.    <div>
12.        <asp:DropDownList ID="DropDownList1" runat="server">
13.        </asp:DropDownList>
14.        <asp:DataList ID="DataList1" runat="server">
15.            <ItemTemplate>
16.                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
17.                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
18.            </ItemTemplate>
19.        </asp:DataList>
20.    </div>
21.    </form>
22.</body>
23.</html>

SelectSqlCommandVB.aspx.vb
01.Imports System.Data
02.Imports System.Data.SqlClient
03.Imports System.Web.Configuration
04. 
05.Partial Class SelectSqlCommandVB
06.    Inherits System.Web.UI.Page
07. 
08.    Private sqlConnection As SqlConnection
09.    Private sqlCommandString As String
10.    Private TableID As String
11.    Private TableData As String
12. 
13.    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
14.        Dim sqlConnectionString As String = WebConfigurationManager.ConnectionStrings("SqlConnectionString").ToString()
15.        sqlConnection = New SqlConnection(sqlConnectionString)
16. 
17.        sqlCommandString = "Select * From [TableDay]" 'กำหนดค่า initial ให้ sqlCommandString
18.        TableID = "DayID" 'มันคือชื่อฟิลด์
19.        TableData = "DayName" 'มันคือชื่อฟิลด์
20. 
21.        If Not IsPostBack Then
22.            'ป้อน ListItem ให้ DropDownList1
23.            DropDownList1.Items.Add(New ListItem("ตารางวัน", "Day"))
24.            DropDownList1.Items.Add(New ListItem("ตารางเดือน", "Month"))
25. 
26.            DropDownList1.Items(0).Selected = True
27.        End If
28. 
29.        DropDownList1.AutoPostBack = True
30. 
31.        BindData()
32.    End Sub
33. 
34.    Private Sub BindData()
35.        Dim sqlCommand As SqlCommand = New SqlCommand(sqlCommandString, sqlConnection)
36.        Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(sqlCommand)
37. 
38.        Dim Dt As DataTable = New DataTable()
39.        sqlDataAdapter.Fill(Dt)
40. 
41.        DataList1.DataSource = Dt
42.        DataList1.DataBind()
43.    End Sub
44. 
45.    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
46.        Select Case DropDownList1.SelectedItem.Value
47.            Case "Day"
48.                sqlCommandString = "Select * From [TableDay]"
49.                TableID = "DayID" 'มันคือชื่อฟิลด์
50.                TableData = "DayName" 'มันคือชื่อฟิลด์
51.            Case "Month"
52.                sqlCommandString = "Select * From [TableMonth]"
53.                TableID = "MonthID" 'มันคือชื่อฟิลด์
54.                TableData = "MonthName" 'มันคือชื่อฟิลด์
55.        End Select
56. 
57.        BindData()
58.    End Sub
59. 
60.    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
61.        Dim LabelBind1 As Label = CType(e.Item.FindControl("Label1"), Label)
62.        Dim LabelBind2 As Label = CType(e.Item.FindControl("Label2"), Label)
63. 
64.        If Not IsNothing(LabelBind1) Then
65.            LabelBind1.Text = DataBinder.Eval(e.Item.DataItem, TableID).ToString()
66.        End If
67. 
68.        If Not IsNothing(LabelBind2) Then
69.            LabelBind2.Text = DataBinder.Eval(e.Item.DataItem, TableData).ToString()
70.        End If
71.    End Sub
72.End Class

Date : 2010-01-21 22:30:58 By : tungman
 

 

No. 6



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



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

ขอบคุณค่ะ...คุณ Tungman
Date : 2010-01-29 11:42:06 By : sunshinesnow
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : โชว์ข้อมูลที่ค้นหาจากหลายตาราง ... ต้องการที่จะแสดงข้อมูลที่ค้นหา....ซึ่งข้อมูลมาจากหลายตารางเป็นดรอปดาวน์ลิสต์ให้ค้นห
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่