dropdownlist触发事件的用法。。。
怎么在dropdownlist中选择一个选项后,触发一个事件。。。比如返回数据库中某张表的某些字段的值。。。然后以一个表格的形式显示在页面上。。。麻烦写个详细代码。。。...
怎么在dropdownlist中选择一个 选项后,触发一个事件。。。比如返回数据库中某张表的某些字段的值。。。然后以一个表格的形式显示在页面上。。。麻烦写个详细代码。。。
展开
展开全部
后置代码:
/// <summary>
/// 绑定数据
/// </summary>
public void Data_Bind()
{
int Id= Convert.ToInt32(DropDownList1.SelectedValue);
this.GridView1.DataSource = GetData_GridView(Id); //指定要根据DropDownList1中的ID获取数据源
this.GridView1.DataBind();
}
/// <summary>
/// 加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
this.DropDownList1.DataSource = GetData_DropDownList1(); //DropDownList1中所需要绑定的数据
this.DropDownList1.DataTextField = "要显示的字段";
this.DropDownList1.DataValueField = "Id";
this.DropDownList1.DataBind();
Data_Bind();
}
}
/// <summary>
/// 根据DropDownList当前选中的值查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Data_Bind();
}
前台:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:GridView ID="GridView1" runat="server">这里自己设置吧</asp:GridView>
/// <summary>
/// 绑定数据
/// </summary>
public void Data_Bind()
{
int Id= Convert.ToInt32(DropDownList1.SelectedValue);
this.GridView1.DataSource = GetData_GridView(Id); //指定要根据DropDownList1中的ID获取数据源
this.GridView1.DataBind();
}
/// <summary>
/// 加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
this.DropDownList1.DataSource = GetData_DropDownList1(); //DropDownList1中所需要绑定的数据
this.DropDownList1.DataTextField = "要显示的字段";
this.DropDownList1.DataValueField = "Id";
this.DropDownList1.DataBind();
Data_Bind();
}
}
/// <summary>
/// 根据DropDownList当前选中的值查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Data_Bind();
}
前台:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:GridView ID="GridView1" runat="server">这里自己设置吧</asp:GridView>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询