比如说 我做个一个博客
有个栏目叫 我的好友
好友的个数 是从数据库里读的 如果有2个好友
那么 我的博客就显示 @好友1 @好友2(@为单选按钮)
我以前做过在线考试,当时设计过单选题
设计的思路是
把@和题(LABLE) 放在 GRIDVIEW里
题从数据库里取
但是GIRDVIEW 是 竖着排的
@题目1
@题目2
@题目3
我想横着排
有个栏目叫 我的好友
好友的个数 是从数据库里读的 如果有2个好友
那么 我的博客就显示 @好友1 @好友2(@为单选按钮)
我以前做过在线考试,当时设计过单选题
设计的思路是
把@和题(LABLE) 放在 GRIDVIEW里
题从数据库里取
但是GIRDVIEW 是 竖着排的
@题目1
@题目2
@题目3
我想横着排
SqlCommand cmd = new SqlCommand("select 好友 from table",con);
SqlDataReader read= cmd.ExecuteReader();
DataTable table = new DataTable();
DataRow r = table.NewRow();
int i =0;
While(read.Read())
{
DataColumn c = new DataColumn(read.GetName(i));
table.Columns.Add(c);
r[i] = read[i].ToString();
i++;
}
table.Rows.Add(r);
this.dataGridView1.DataSource = table.DefaultView;
SqlCommand cmd = new SqlCommand("select 好友 from table",con);
SqlDataReader read= cmd.ExecuteReader();
DataTable table = new DataTable();
DataRow r = table.NewRow();
int i =0;
While(read.Read())
{
DataColumn c = new DataColumn(read.GetName(i));
table.Columns.Add(c);
r[i] = read[i].ToString();
i++;
}
table.Rows.Add(r);
this.dataGridView1.DataSource = table.DefaultView;
参考