|
|
|
dropdownlist แปรผันตามกัน ค่ะ เรามี dropdownlist อยู่ 2 ตัว เวลาเลือกที่ dropdownlist 1 |
|
|
|
|
|
|
|
รบกวนช่วยแนะให้หน่อยนะคะ ^^
|
|
|
|
|
Date :
2010-02-02 11:34:43 |
By :
tar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เคยเขียนไว้แล้ว แต่หาที่โพสต์ไว้ไม่เจอ
ใช้ asp.net ajax เป็นไหม
LinkDropDownList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LinkDropDownList.aspx.cs" Inherits="LinkDropDownList" %>
<!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>
<script type="text/javascript">
function pageLoad() {
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<br />
<br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
LinkDropDownList.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 LinkDropDownList : System.Web.UI.Page
{
SqlConnection sqlConnection;
protected void Page_Load(object sender, EventArgs e)
{
string sqlConnectionString = WebConfigurationManager.ConnectionStrings["SqlConnectionString"].ToString();
sqlConnection = new SqlConnection(sqlConnectionString);
DropDownList1.AutoPostBack = true;
DropDownList1.DataSource = ProvinceData();
DropDownList1.DataValueField = "ProvinceID";
DropDownList1.DataTextField = "ProvinceName";
DropDownList1.SelectedIndexChanged += new EventHandler(DropDownList1_SelectedIndexChanged);
if (!IsPostBack)
{
DropDownList1.DataBind();
DropDownList2.DataSource = DistrictData(1);
DropDownList2.DataValueField = "DistrictID";
DropDownList2.DataTextField = "DistrictName";
DropDownList2.DataBind();
}
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList2.DataSource = DistrictData(int.Parse(DropDownList1.SelectedItem.Value));
DropDownList2.DataValueField = "DistrictID";
DropDownList2.DataTextField = "DistrictName";
DropDownList2.DataBind();
}
private DataTable ProvinceData()
{
DataTable Dt = new DataTable();
string sqlCommandString = "Select * From [Global_Province]";
SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
SqlDataAdapter sqldataAdapter = new SqlDataAdapter(sqlCommand);
sqldataAdapter.Fill(Dt);
return Dt;
}
private DataTable DistrictData(int ProvinceID)
{
DataTable Dt = new DataTable();
string sqlCommandString = "Select * From [Global_District] Where [ProvinceID]=@ProvinceID";
SqlCommand sqlCommand = new SqlCommand(sqlCommandString, sqlConnection);
sqlCommand.Parameters.Add("@ProvinceID", SqlDbType.Int).Value = ProvinceID;
SqlDataAdapter sqldataAdapter = new SqlDataAdapter(sqlCommand);
sqldataAdapter.Fill(Dt);
return Dt;
}
}
|
|
|
|
|
Date :
2010-02-02 12:13:45 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เคยใช้แต่ ajax แบบ jquery ค่ะ แต่ว่าเว็บที่เขียนมันใช้ ajax แบบ jquery ไม่ได้ เพราะเป็นเว็บบน mobile ค่ะ
ไม่รองรับ java script
|
|
|
|
|
Date :
2010-02-02 13:30:56 |
By :
tar |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แก้นิดหน่อยก็ไม่ ajax แล้วครับ แต่ไม่รู้ใช้กับ mobile ได้หรือเปล่า
LinkDropDownList.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="LinkDropDownList.aspx.cs" Inherits="LinkDropDownList" %>
<!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>
<br />
<br />
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</div>
</form>
</body>
</html>
|
|
|
|
|
Date :
2010-02-02 14:22:15 |
By :
tungman |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณมากนะคะ เด๋วจะลองทำดู ^^
|
|
|
|
|
Date :
2010-02-02 14:30:05 |
By :
boo |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|