ASP.Net:需要有关绑定到数据库列的下拉列表的帮助
我创建了数据库,其中包含
- MemName
- monthlyAmt
- CurrentInstAmt
我已使用 DropDownList 框绑定 Memname 列的列;
在 DropDownList 框中选择 memname 值时,currentInstAmt 和 monthlyamt 的相应值应显示在 Textbox 中。
我是 ASP.NET
代码的初学者 -
DataSet dsMemname = new DataSet();
try
{
con.ConnectionString = strcon;
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Memcollection";
SqlDataAdapter adp = new SqlDataAdapter(cmd.CommandText, con);
adp.Fill(dsMemname);
ddlmemname.DataTextField = "MemName";
ddlmemname.DataSource = dsMemname;
ddlmemname.DataBind();
}
catch (Exception ex)
{
throw ex;
}
I have created database which has columns
- MemName
- monthlyAmt
- CurrentInstAmt
I have bound the Memname column with a DropDownList box;
onselection of memname value in DropDownList box, the corresponding values of currentInstAmt and monthlyamt should be displayed in Textbox.
I am beginer in asp.net
code -
DataSet dsMemname = new DataSet();
try
{
con.ConnectionString = strcon;
con.Open();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "usp_Memcollection";
SqlDataAdapter adp = new SqlDataAdapter(cmd.CommandText, con);
adp.Fill(dsMemname);
ddlmemname.DataTextField = "MemName";
ddlmemname.DataSource = dsMemname;
ddlmemname.DataBind();
}
catch (Exception ex)
{
throw ex;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:
首先,设置下拉列表的 DataValueField,就像 DataTextField 一样:
END EDIT
设置下拉列表的
autopostback="True"
如下:然后在后面的代码中为您的页面,为下拉列表添加一个事件,如下所示:
两个 get() 方法是您自己的代码,用于查找相关值。此外,您可能希望以某种方式将它们优化为一次调用,具体取决于您从何处提取它们以及性能考虑因素。
EDIT:
First, set your dropdownlist's DataValueField, just like the DataTextField: as so:
END EDIT
Set your dropdownlist's
autopostback="True"
as so:and then in the code behind for your page, add an event for your drop down as so:
The two get() methods are your own code to look up your relevant values. Also, you may want to optimize them to one call in some manner depending on where you're pulling them from and performance considerations.