[英]Transform integer to numeric list in combobox from db - C#
I have a table called "Shoppings" in my SQL db. 我的SQL数据库中有一个名为“购物”的表。 This one has a column called qtPisos, which describes how many levels a shopping mall has. 这个有一个叫做qtPisos的列,它描述了一个购物中心有多少层。 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;
You can retrieve the value of the levels and then create a numeric array using this value as the maximum value: 您可以检索级别的值,然后使用此值作为最大值创建数字数组:
var levels = Enumerable.Range(1, levels)
You can then bind this value to a DropDownlist control or such. 然后,您可以将此值绑定到DropDownlist控件等。
control.Source = levels;
control.Bind()
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. 若要显示该级别的商店列表,可以使用DropDownList的自动回发功能,并根据控件的SelectedValue属性检索商店。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.