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,028

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



 

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

 



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 : 1797 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
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SelectSqlCommand.aspx.cs" Inherits="SelectSqlCommand" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

SelectSqlCommand.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Data.SqlClient;
using System.Web.Configuration;

public partial class SelectSqlCommand : System.Web.UI.Page
{
    private string sqlCommandString;
    private string TableID;
    private string TableData;

    protected void Page_Load(object sender, EventArgs e)
    {
        sqlCommandString = "Select * From [TableDay]"; //กำหนดค่า initial ให้ sqlCommandString
        TableID = "DayID"; //มันคือชื่อฟิลด์
        TableData = "DayName"; //มันคือชื่อฟิลด์

        if (!IsPostBack)
        {
            //ป้อน ListItem ให้ DropDownList1
            DropDownList1.Items.Add(new ListItem("ตารางวัน", "Day"));
            DropDownList1.Items.Add(new ListItem("ตารางเดือน", "Month"));

            DropDownList1.Items[0].Selected = true;
        }

        DropDownList1.AutoPostBack = true;
        DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);

        DataList1.ItemDataBound += new DataListItemEventHandler(DataList1_ItemDataBound);

        BindData();
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        switch (DropDownList1.SelectedItem.Value)
        { 
            case "Day":
                sqlCommandString = "Select * From [TableDay]";
                TableID = "DayID"; //มันคือชื่อฟิลด์
                TableData = "DayName"; //มันคือชื่อฟิลด์
                break;
            case "Month":
                sqlCommandString = "Select * From [TableMonth]";
                TableID = "MonthID"; //มันคือชื่อฟิลด์
                TableData = "MonthName"; //มันคือชื่อฟิลด์
                break;
        }

        BindData();
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        Label LabelBind1 = (Label)(e.Item.FindControl("Label1"));
        Label LabelBind2 = (Label)(e.Item.FindControl("Label2"));

        if (LabelBind1 != null)
            LabelBind1.Text = DataBinder.Eval(e.Item.DataItem, TableID).ToString();

        if (LabelBind2 != null)
            LabelBind2.Text = DataBinder.Eval(e.Item.DataItem, TableData).ToString();
    }

    private void BindData()
    {
        string sqlConnectionString = WebConfigurationManager.ConnectionStrings["SqlConnectionString"].ToString();
        SqlConnection sqlConnection = new SqlConnection(sqlConnectionString);

        SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
        SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand);

        DataTable Dt = new DataTable();
        sqlDataAdapter.Fill(Dt);

        DataList1.DataSource = Dt;
        DataList1.DataBind();
    }
}

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
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="SelectSqlCommandVB.aspx.vb" Inherits="SelectSqlCommandVB" %>

<!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 runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
                <asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

SelectSqlCommandVB.aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class SelectSqlCommandVB
    Inherits System.Web.UI.Page

    Private sqlConnection As SqlConnection
    Private sqlCommandString As String
    Private TableID As String
    Private TableData As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sqlConnectionString As String = WebConfigurationManager.ConnectionStrings("SqlConnectionString").ToString()
        sqlConnection = New SqlConnection(sqlConnectionString)

        sqlCommandString = "Select * From [TableDay]" 'กำหนดค่า initial ให้ sqlCommandString
        TableID = "DayID" 'มันคือชื่อฟิลด์
        TableData = "DayName" 'มันคือชื่อฟิลด์

        If Not IsPostBack Then
            'ป้อน ListItem ให้ DropDownList1
            DropDownList1.Items.Add(New ListItem("ตารางวัน", "Day"))
            DropDownList1.Items.Add(New ListItem("ตารางเดือน", "Month"))

            DropDownList1.Items(0).Selected = True
        End If

        DropDownList1.AutoPostBack = True

        BindData()
    End Sub

    Private Sub BindData()
        Dim sqlCommand As SqlCommand = New SqlCommand(sqlCommandString, sqlConnection)
        Dim sqlDataAdapter As SqlDataAdapter = New SqlDataAdapter(sqlCommand)

        Dim Dt As DataTable = New DataTable()
        sqlDataAdapter.Fill(Dt)

        DataList1.DataSource = Dt
        DataList1.DataBind()
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Select Case DropDownList1.SelectedItem.Value
            Case "Day"
                sqlCommandString = "Select * From [TableDay]"
                TableID = "DayID" 'มันคือชื่อฟิลด์
                TableData = "DayName" 'มันคือชื่อฟิลด์
            Case "Month"
                sqlCommandString = "Select * From [TableMonth]"
                TableID = "MonthID" 'มันคือชื่อฟิลด์
                TableData = "MonthName" 'มันคือชื่อฟิลด์
        End Select

        BindData()
    End Sub

    Protected Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles DataList1.ItemDataBound
        Dim LabelBind1 As Label = CType(e.Item.FindControl("Label1"), Label)
        Dim LabelBind2 As Label = CType(e.Item.FindControl("Label2"), Label)

        If Not IsNothing(LabelBind1) Then
            LabelBind1.Text = DataBinder.Eval(e.Item.DataItem, TableID).ToString()
        End If

        If Not IsNothing(LabelBind2) Then
            LabelBind2.Text = DataBinder.Eval(e.Item.DataItem, TableData).ToString()
        End If
    End Sub
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 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

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