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

HOME > .NET Framework > Forum > ทำ search แบบ dropdownlist แบบ web นี้คับ ใช้ C# อยากรู้วิธีทำ คราวๆ หรือมี code ก็ดีคับ



 

ทำ search แบบ dropdownlist แบบ web นี้คับ ใช้ C# อยากรู้วิธีทำ คราวๆ หรือมี code ก็ดีคับ

 



Topic : 025875

Guest




http://www.notebookspec.com/2008/

แบบ web นี้คับ

ใช้ C# อยากรู้วิธีทำ คราวๆ หรือมี code ก็ดีคับ



Tag : - - - -







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2009-03-26 23:02:53 By : AOA View : 2737 Reply : 2
 

 

No. 1



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

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

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

Code (C#)
<%@ Page Language="C#" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
		String strKeyWord;
		void Page_Load(object sender,EventArgs e)		
		{
			strKeyWord = this.txtKeyWord.Text;
		}

		void BindData()
		{
			OleDbConnection objConn = new OleDbConnection();
			OleDbCommand objCmd = new OleDbCommand();
			OleDbDataAdapter dtAdapter = new OleDbDataAdapter();
			DataSet ds = new DataSet();
			String strConnString,strSQL;

			strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + 
			Server.MapPath("database/mydatabase.mdb")+";Jet OLEDB:Database Password=;";
			strSQL = "SELECT * FROM customer WHERE (Name like '%"+ strKeyWord +"%' OR Email like '%"+ strKeyWord +"%') ";

			objConn.ConnectionString = strConnString;
			objCmd.Connection = objConn;
			objCmd.CommandText = strSQL	;
			objCmd.CommandType = CommandType.Text;


			dtAdapter.SelectCommand = objCmd;

			dtAdapter.Fill(ds);

			//*** BindData to GridView ***//
			myGridView.DataSource = ds;
			myGridView.DataBind();

			dtAdapter = null;		
			objConn.Close();
			objConn = null;

	}

	void myGridView_RowDataBound(Object s, GridViewRowEventArgs e) 
	{
		//*** CustomerID ***//
		Label lblCustomerID = (Label)(e.Row.FindControl("lblCustomerID"));
		if (lblCustomerID != null)
		{
			lblCustomerID.Text = (string)DataBinder.Eval(e.Row.DataItem, "CustomerID");
		}

		//*** Email ***//
		Label lblName = (Label)(e.Row.FindControl("lblName"));
		if (lblName != null)
		{
			lblName.Text = (string)DataBinder.Eval(e.Row.DataItem, "Name");
		}

		//*** Name ***//
		Label lblEmail = (Label)(e.Row.FindControl("lblEmail"));
		if (lblEmail != null)
		{
			lblEmail.Text = (string)DataBinder.Eval(e.Row.DataItem, "Email");
		}

		//*** CountryCode ***//
		Label lblCountryCode = (Label)(e.Row.FindControl("lblCountryCode"));
		if (lblCountryCode != null)
		{
			lblCountryCode.Text = (string)DataBinder.Eval(e.Row.DataItem, "CountryCode");
		}

		//*** Budget ***//
		Label lblBudget = (Label)(e.Row.FindControl("lblBudget"));
		if (lblBudget != null)
		{
			lblBudget.Text = DataBinder.Eval(e.Row.DataItem, "Budget").ToString();
		}

		//*** Used ***//
		Label lblUsed = (Label)(e.Row.FindControl("lblUsed"));
		if (lblUsed != null)
		{
			lblUsed.Text = DataBinder.Eval(e.Row.DataItem, "Used").ToString();
		}
	}

	void btnSearch_Click(Object sender, EventArgs e)
	{
		BindData();
	}

</script>
<html>
<head>
    <title>ThaiCreate.Com ASP.NET - Microsoft Access</title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:Label id="lblKeyword" runat="server" text="Keyword"></asp:Label>
        <asp:TextBox id="txtKeyWord" runat="server"></asp:TextBox>
        <asp:Button id="btnSearch" onclick="btnSearch_Click" runat="server" Text="Search"></asp:Button>
        <br />
        <br />
        <asp:GridView id="myGridView" runat="server"
		AutoGenerateColumns="False" onRowDataBound="myGridView_RowDataBound">
            <HeaderStyle backcolor="#cccccc"></HeaderStyle>
            <AlternatingRowStyle backcolor="#e8e8e8"></AlternatingRowStyle>
            <Columns>
                <asp:TemplateField HeaderText="CustomerID">
                    <ItemTemplate>
                        <asp:Label id="lblCustomerID" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label id="lblName" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Email">
                    <ItemTemplate>
                        <asp:Label id="lblEmail" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="CountryCode">
                    <ItemTemplate>
                        <asp:Label id="lblCountryCode" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Budget">
                    <ItemTemplate>
                        <asp:Label id="lblBudget" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Used">
                    <ItemTemplate>
                        <asp:Label id="lblUsed" runat="server"></asp:Label> 
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>
    </form>
</body>
</html>







Date : 2009-03-27 07:13:44 By : webmaster
 


 

No. 2



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



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


ถ้าเป็นผมนะ (.NET 2.0 + VS2005 + MSSQL 2000,2005)
====================================================
1) สร้าง StoreProcedure

Create GetBrand Procedure
CREATE PROCEDURE Brand_GetBrands
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT *
FROM Brand
END


2) เมื่อสร้างเสร็จแล้ว ให้ไป Add New Item > DataSet
3) ที่ Workspace ของ DataSet ให้คลิ๊กขวา เลือก Add TableAdapter จากเลือกเลือก Use Existng Storeprocedure เลือก Store Brand_GetBrands จากนั้นก็ Next ไปเรือยๆๆ เมื่อสร้างเสร็จแล้วให้แก้ชื่อ DataTable > เป็น Brand (ตรงนี้แล้วแต่นะครับ) ถ้าแก้แล้วชื่อของ TableAdapter จะเปลี่ยนตามเป็น BrandTableAdapter
4) กลับมาที่ WebPage วาง ObjectDataSource แก้ชื่อเป็น BrandDataSource จากนั้น Config DataSource > เลือก Class: BrandTableAdapter ที่ Select Tab ให้เลือก GetData (ชื่อ method เดียวกับ TableAdapter ที่เราสร้างในข้อ 3)
5) จากนั้นวาง Dropdownlist > Config DataSource = BrandDataSource เลือก Feild Text Id = {Brand Name}, Field Value Id = {Brand Id}
6) ที่ Dropdownlist เลือก Edit Item เพิ่ม List Item:
Text: ==== เลือกทั้งหมด =====
Value: 0 <== ใส่ค่าอะไรก็ได้ที่ทำให้เวลา Search รู้ว่า เลือกทั้งหมด (ปกติผมจะใส่ 0)
Set Property: AppendDataBoundItem = True
Date : 2009-03-27 09:19:23 By : jezusmitsui
 

   

ค้นหาข้อมูล


   
 

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