我有一个在更新面板内的表单,并使用bootstrap模式触发。我有一个级联列表。首次DropDownList
更改后,第二个DropDownList
应加载。但是在第一次DropDownList
更改后页面重新加载。
<asp:UpdatePanel ID="updPanel1" runat="server" UpdateMode="Conditional" >
<ContentTemplate>
<div class="modal fade" tabindex="-1" role="dialog" id="yenitalep">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Form</h4>
</div>
<div class="modal-body">
<div class="form-group">
<label for="envanter">Tip</label>
<asp:DropDownList ID="ddlTip" runat="server" CssClass="form-control" OnSelectedIndexChanged="ddlTip_SelectedIndexChanged"></asp:DropDownList>
</div>
<div class="form-group">
<asp:DropDownList ID="ddlTip1" runat="server" CssClass="form-control level1"></asp:DropDownList>
</div>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlTip" />
</Triggers>
</asp:UpdatePanel>
C#代码背后:
protected void ddlTip_SelectedIndexChanged(object sender, EventArgs e)
{
short id = short.Parse(ddlTip.SelectedValue);
List<servisTipleri> list = ServisTipController.childs(id);
ddlTip1.DataSource = list;
ddlTip1.DataTextField = "title";
ddlTip1.DataValueField = "id";
ddlTip1.DataBind();
}
如何在不刷新页面的情况下加载第二个DDL。
答案 0 :(得分:1)
只需将更新面板置于模式#include <stdio.h>
int main()
{
int array[11] = { 1, 5, 9, 15, 37, 49, 56, 65, 74, 90, 95};
int first = 0;
int last = 10;
int search = 95;
int middle = (first+last)/2;
while (first <= last) {
if (array[middle] < search)
first = middle + 1;
else if (array[middle] > search)
last = middle - 1;
else break;
printf("first= %d,last= %d, middle= %d, search= %d\n", first, last, middle, search);
middle = (first + last)/2;
}
printf("middle = %d\n", array[middle]);
}
:
<div>
答案 1 :(得分:0)
这是我做的方式,对我来说很好。我希望这会对你有所帮助。
这是我的x_dropdownDemo_no_postback.aspx文件。
<form id="form1" runat="server">
<%=DateTime.Now.ToString() %>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="updPanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="ddlTip" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTip_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:DropDownList ID="ddlTip1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTip1_SelectedIndexChanged">
</asp:DropDownList>
<br />
<asp:DropDownList ID="ddlTip2" runat="server">
</asp:DropDownList>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlTip" />
<asp:AsyncPostBackTrigger ControlID="ddlTip1" />
</Triggers>
</asp:UpdatePanel>
</form>
这是我的x_dropdownDemo_no_postback.cs文件。
public partial class x_dropdownDemo_no_postback:System.Web.UI.Page {
private static string connStr = System.Configuration.ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString;
MySqlConnection Conn = new MySqlConnection(ConfigurationManager.ConnectionStrings["DBConnString"].ConnectionString);
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Binddropdown();
}
}
protected void Binddropdown()
{
Conn.Open();
MySqlCommand cmd = new MySqlCommand("select * from Countries", Conn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
ddlTip.DataSource = ds;
ddlTip.DataTextField = "Name";
ddlTip.DataValueField = "Id";
ddlTip.DataBind();
ddlTip.Items.Insert(0, new ListItem("--select--", "0"));
ddlTip1.Items.Insert(0, new ListItem("--select--", "0"));
ddlTip2.Items.Insert(0, new ListItem("--select--", "0"));
}
protected void ddlTip_SelectedIndexChanged(object sender, EventArgs e)
{
int ddlTipId = Convert.ToInt32(ddlTip.SelectedValue);
Conn.Open();
MySqlCommand cmd = new MySqlCommand("select * from State where Country_Id=" + ddlTipId, Conn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
ddlTip1.DataSource = ds;
ddlTip1.DataTextField = "Name";
ddlTip1.DataValueField = "Id";
ddlTip1.DataBind();
ddlTip1.Items.Insert(0, new ListItem("--select--", "0"));
if (ddlTip1.SelectedValue == "0")
{
ddlTip2.Items.Clear();
ddlTip2.Items.Insert(0, new ListItem("--select--", "0"));
}
}
protected void ddlTip1_SelectedIndexChanged(object sender, EventArgs e)
{
int ddlTip1Id = Convert.ToInt32(ddlTip.SelectedValue);
Conn.Open();
MySqlCommand cmd = new MySqlCommand("select * from Region where State_Id=" + ddlTip1Id, Conn);
MySqlDataAdapter da = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
Conn.Close();
ddlTip2.DataSource = ds;
ddlTip2.DataTextField = "Name";
ddlTip2.DataValueField = "Id";
ddlTip2.DataBind();
ddlTip2.Items.Insert(0, new ListItem("--select--", "0"));
}
}