从数据表计数行添加按钮? [英] Add buttons from datatable count row?

查看:57
本文介绍了从数据表计数行添加按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!

我需要有关此问题的帮助:

我在sql和Group表中有Items表!

我需要什么:

在窗体的加载事件上,我想向组表中的行数显示按钮,并且按钮必须具有组名称的文本!

在显示按钮之后,我要在按钮上显示项目,并且当我单击项目按钮时,按钮的事件必须为单击".单击按钮后,列表框必须填充项目表中的数据!


P.S.对不起,我的英语!....

Hello!

I need help with this problem:

I have Items table in sql and Group table!

What i need:

on load event of form i want to show Buttons to number of rows in Group Table and Buttons must have text of grup name!

After the buttons are displayed i want to show items on buttons and when i click a item button , the event of buttons must be Click. After clicking button listbox must be filled with data from items table!


P.S .Sorry for my english!....

推荐答案

这应该让您入门
This should get you started
using(SqlConnection conn = new SqlConnection(...))
{
  using(SqlCommand cmd = new SqlCommand("SELECT ID, Name FROM Group", conn))
  {
    DataReader dr = cmd.ExecuteReader();
    while(dr.Read())
    {
       Button btn = new Button();
       btn.Text = dr["Name"].ToString();
       btn.CommandArgument = dr["ID"].ToString();
       btn.Command += new CommandEventHandler(OnBtnCommand);
       Controls.Add(btn);
    }
  }
}

protected void OnBtnCommand(object sender, CommandEventArgs e)
{
   // Load dropdown based on 
   int ID = int.Parse(e.CommandArgument);
}


这篇关于从数据表计数行添加按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆