dropdownlist的OnSelectedIndexChanged怎么做
drpLev1.DataSource=SW.BS.Facade.FTrainInfo.GetParentNode();drpLev1.DataTextField="Tra...
drpLev1.DataSource = SW.BS.Facade.FTrainInfo.GetParentNode();
drpLev1.DataTextField = "TrainTypeName";
drpLev1.DataValueField = "ID";
drpLev1.DataBind();
int pid = Convert.ToInt32(drpLev1.DataValueField);
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
怎样再将这两个关联起来???
OnSelectedIndexChanged在后台怎么写??? 展开
drpLev1.DataTextField = "TrainTypeName";
drpLev1.DataValueField = "ID";
drpLev1.DataBind();
int pid = Convert.ToInt32(drpLev1.DataValueField);
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
怎样再将这两个关联起来???
OnSelectedIndexChanged在后台怎么写??? 展开
展开全部
明白你的意思了。
你在设计视图点击drpLev1这个控件,然后按F4键,在右侧的属性栏里点击事件(雷)按钮,然后找到OnSelectedIndexChanged 事件,,双击,这时后台就会生成一个它的事件,然后你把下面的代码贴进去
int pid = Convert.ToInt32(drpLev1.DataValueField);
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
不过我感觉下面这句可能有问题,你应该改成int pid = Convert.ToInt32(drpLev1.SelecedValue)
int pid = Convert.ToInt32(drpLev1.DataValueField);
另外,drpLev1控件,你还要设置一个属性 AutoPostBack=true
你在设计视图点击drpLev1这个控件,然后按F4键,在右侧的属性栏里点击事件(雷)按钮,然后找到OnSelectedIndexChanged 事件,,双击,这时后台就会生成一个它的事件,然后你把下面的代码贴进去
int pid = Convert.ToInt32(drpLev1.DataValueField);
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
不过我感觉下面这句可能有问题,你应该改成int pid = Convert.ToInt32(drpLev1.SelecedValue)
int pid = Convert.ToInt32(drpLev1.DataValueField);
另外,drpLev1控件,你还要设置一个属性 AutoPostBack=true
展开全部
你的代码:
drpLev1.DataSource = SW.BS.Facade.FTrainInfo.GetParentNode();
drpLev1.DataTextField = "TrainTypeName";
drpLev1.DataValueField = "ID";
drpLev1.DataBind();
protected void drpLev1_SelectedIndexChanged(object sender, EventArgs e)
{
drpLev2.Items.Clear();
int pid = Convert.ToInt32(drpLev1.SelectedValue);
//这里是SelectedValue属性 ,不是DataValueField 字段
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
}
先看看我的例子:
前台:
<asp:DropDownList ID="DDL1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DDL2" runat="server" AutoPostBack="True" ">
</asp:DropDownList>
后台代码:
private void DataBindDDL1() //绑定DDL1的数据
{
string strSql = "select sname, childID from T1";
DataSet ds = SqlDBOperate.TheOnly.GetDataSet(strSql, "T1");
DDL1.DataSource = ds.Tables["T1"];
DDL1.DataTextField = "sname";
DDL1.DataValueField = "childID";
DDL1.DataBind();
}
private void DataBindDDL2() //绑定DDL2的数据
{
string strSql = string.Format("select childID , sname from T2 WHERE ID IN ( SELECT childID from T1 WHERE childID = '{0}')", DDL1.SelectedValue);
DataSet ds = SqlDBOperate.TheOnly.GetDataSet(strSql, "T2");
DDL2.DataSource = ds.Tables["T2"];
DDL2.DataTextField = "sname";
DDL2.DataValueField = "childID";
DDL2.DataBind();
}
//在DDL1的SelectedIndexChanged()事件里面写绑定DDL2的数据
protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
{
DDL2.Items.Clear();
DataBindDDL2();
}
drpLev1.DataSource = SW.BS.Facade.FTrainInfo.GetParentNode();
drpLev1.DataTextField = "TrainTypeName";
drpLev1.DataValueField = "ID";
drpLev1.DataBind();
protected void drpLev1_SelectedIndexChanged(object sender, EventArgs e)
{
drpLev2.Items.Clear();
int pid = Convert.ToInt32(drpLev1.SelectedValue);
//这里是SelectedValue属性 ,不是DataValueField 字段
drpLev2.DataSource = SW.BS.Facade.FTrainInfo.GetSonNode(pid);
drpLev2.DataTextField = "TrainTypeName";
drpLev2.DataValueField = "ID";
drpLev2.DataBind();
}
先看看我的例子:
前台:
<asp:DropDownList ID="DDL1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DDL1_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DDL2" runat="server" AutoPostBack="True" ">
</asp:DropDownList>
后台代码:
private void DataBindDDL1() //绑定DDL1的数据
{
string strSql = "select sname, childID from T1";
DataSet ds = SqlDBOperate.TheOnly.GetDataSet(strSql, "T1");
DDL1.DataSource = ds.Tables["T1"];
DDL1.DataTextField = "sname";
DDL1.DataValueField = "childID";
DDL1.DataBind();
}
private void DataBindDDL2() //绑定DDL2的数据
{
string strSql = string.Format("select childID , sname from T2 WHERE ID IN ( SELECT childID from T1 WHERE childID = '{0}')", DDL1.SelectedValue);
DataSet ds = SqlDBOperate.TheOnly.GetDataSet(strSql, "T2");
DDL2.DataSource = ds.Tables["T2"];
DDL2.DataTextField = "sname";
DDL2.DataValueField = "childID";
DDL2.DataBind();
}
//在DDL1的SelectedIndexChanged()事件里面写绑定DDL2的数据
protected void DDL1_SelectedIndexChanged(object sender, EventArgs e)
{
DDL2.Items.Clear();
DataBindDDL2();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
直接把drplev2的绑定过程放到里面去
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询