将组合框中的整数从 db 转换为数字列表 - C#
我的 SQL 数据库中有一个名为“Shoppings”的表。这个有一个名为qtPisos的列,它描述了一个购物中心有多少层。在我的程序中,我想根据该整数的数量创建一个组合框,以便用户可以选择购物中心中的级别,然后购物中心将列出该特定级别的商店。
知道我该怎么做吗?
这是我的代码。
public partial class Shoppings : Form
{
private DataViewManager dsView;
private DataSet ds;
public Shoppings()
{
InitializeComponent();
}
private void Shoppings_Load(object sender, EventArgs e)
{
Login logForm = new Login();
logForm = logForm.getLoginForm();
ds = new DataSet("DsShoppings");
// Fill the Dataset with Shoppings, map Default Tablename "Table" to "Shoppings".
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Shoppings", logForm.sqlConnection);
sda.TableMappings.Add("Table", "Shoppings");
sda.Fill(this.ds);
// The DataViewManager returned by the DefaultViewManager property
// allows to create custom settings for each DataTable in the DataSet.
this.dsView = ds.DefaultViewManager;
// Combobox Databinding
ComboShopping.DataSource = this.dsView;
ComboShopping.DisplayMember = "Shoppings.nomeShopping";
ComboShopping.ValueMember = "Shoppings.idShopping";
// Text Columns DataBinding
txtTotalLojas.DataBindings.Add("Text", dsView, "Shoppings.totalLojas");
//int qtPisos = Convert.ToInt32(ds.Tables["Shoppings"].Rows[0]["qtPisos"]);
ComboPisos.DataSource = this.dsView;
I have a table called "Shoppings" in my SQL db. This one has a column called qtPisos, which describes how many levels a shopping mall has. In my program I would like to create a combobox based on the quantity of this integer, so the user can select the level in the shopping mall, which will then list the shops for that particular level.
Any idea how can I do that?
Here is my code.
public partial class Shoppings : Form
{
private DataViewManager dsView;
private DataSet ds;
public Shoppings()
{
InitializeComponent();
}
private void Shoppings_Load(object sender, EventArgs e)
{
Login logForm = new Login();
logForm = logForm.getLoginForm();
ds = new DataSet("DsShoppings");
// Fill the Dataset with Shoppings, map Default Tablename "Table" to "Shoppings".
SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM Shoppings", logForm.sqlConnection);
sda.TableMappings.Add("Table", "Shoppings");
sda.Fill(this.ds);
// The DataViewManager returned by the DefaultViewManager property
// allows to create custom settings for each DataTable in the DataSet.
this.dsView = ds.DefaultViewManager;
// Combobox Databinding
ComboShopping.DataSource = this.dsView;
ComboShopping.DisplayMember = "Shoppings.nomeShopping";
ComboShopping.ValueMember = "Shoppings.idShopping";
// Text Columns DataBinding
txtTotalLojas.DataBindings.Add("Text", dsView, "Shoppings.totalLojas");
//int qtPisos = Convert.ToInt32(ds.Tables["Shoppings"].Rows[0]["qtPisos"]);
ComboPisos.DataSource = this.dsView;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以检索级别的值,然后使用该值作为最大值创建一个数值数组:
然后可以将该值绑定到 DropDownlist 控件等。
然后,要显示该级别的商店列表,您可以使用 DropDownList 的自动回发功能并根据控件的 SelectedValue 属性检索商店。
You can retrieve the value of the levels and then create a numeric array using this value as the maximum value:
You can then bind this value to a DropDownlist control or such.
To then display a list of shops for that level, you could use the DropDownList's autopostback feature and retrieve your shops based upon the SelectedValue property of the control.