|
|
|
รบกวนสอบถามเรื่อง Dropdown หน่อยครับเกี่ยวกับการ ผูกข้อมูล 2 Dropdown |
|
|
|
|
|
|
|
รบกวนถามหน่อยครับเกี่ยวกับการผูก Dropdown จังหวัดกับ อำเภอ พอเข้ามาแล้วมันดึงข้อมูลของจังหวัดแต่พอคลิกจังหวัดแล้วมันขึ้นรูปแบบนี้อะครับ
staff.aspx
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlProvince" runat="server" width="142px"
DataSourceID="SqlDataSource1" DataTextField="PROVINCE_NAME_TH"
DataValueField="PROVINCE_ID"
onselectedindexchanged="ddlProvince_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>-</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:RMUTRConnectionString %>"
SelectCommand="SELECT [PROVINCE_ID], [PROVINCE_NAME_TH] FROM [REF_PROVINCE]">
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
<!--End Province-->
<asp:UpdatePanel ID="UpdatePanel2" runat="server">
<ContentTemplate>
<asp:DropDownList ID="ddlAmphur" runat="server" width="142px"
AutoPostBack="True"
onselectedindexchanged="ddlAmphur_SelectedIndexChanged"
DataSourceID="SqlDataSource9" DataTextField="DISTRICT_NAME_TH"
DataValueField="DISTRICT_ID">
<asp:ListItem>-</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource9" runat="server"
ConnectionString="<%$ ConnectionStrings:RMUTRConnectionString %>"
SelectCommand="SELECT [DISTRICT_ID], [DISTRICT_NAME_TH] FROM [REF_DISTRICT]">
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
<!-- End Amphur-->
staff.aspx.cs
protected void ddlProvince_SelectedIndexChanged(object sender, EventArgs e)
{
String strSQL;
strSQL = "SELECT DISTRICT_ID,DISTRICT_NAME_TH FROM REF_DISTRICT WHERE PROVINCE_ID = '" + ddlProvince.SelectedValue + "' ";
ddlAmphur.DataSource = clsDB.QueryDataTable(strSQL);
ddlAmphur.DataTextField = "DISTRICT_NAME_TH";
ddlAmphur.DataValueField = "DISTRICT_ID";
ddlAmphur.DataBind();
}
protected void ddlAmphur_SelectedIndexChanged(object sender, EventArgs e)
{
String strSQL;
strSQL = "SELECT DISTRICT_ID,DISTRICT_NAME_TH FROM REF_DISTRICT WHERE PROVINCE_ID = '" + ddlAmphur.SelectedValue + "' ";
ddlAmphur.DataSource = clsDB.QueryDataTable(strSQL);
ddlAmphur.DataTextField = "DISTRICT_NAME_TH";
ddlAmphur.DataValueField = "DISTRICT_ID";
ddlAmphur.DataBind();
}
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), C#, VS 2010 (.NET 4.x)
|
|
|
|
|
|
Date :
2013-07-26 14:10:28 |
By :
offonepoint |
View :
884 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (C#)
DataList1.DataSourceID = null;
DataList1.DataSource = objPds;
DataList1.DataBind();
|
|
|
|
|
Date :
2013-07-27 19:39:37 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|