vb.net数据库填充列表
这是asp.net下数据库填充列表的例子for (int i = 0; i < Ds.Tables["adminlist"].Rows.Count; i++)
{
TableRow tr = new TableRow();
TableCell td1 = new TableCell();
TableCell td2 = new TableCell();
TableCell td3 = new TableCell();
TableCell td4 = new TableCell();
TableCell td5 = new TableCell();
td1.Controls.Add(new LiteralControl(Convert.ToString(i + 1)));
td2.Controls.Add(new LiteralControl("<input ID='chuser' type='checkbox'/>"));
td3.Controls.Add(new LiteralControl(Ds.Tables["adminlist"].Rows[i]["adminname"].ToString()));
td4.Controls.Add(new LiteralControl(Ds.Tables["adminlist"].Rows[i]["adminpassword"].ToString()));
td5.Controls.Add(new LiteralControl("<a href='modifyadmin.aspx?ID=" + Ds.Tables["adminlist"].Rows[i]["adminid"].ToString() + " '>修改</a>"));
tr.Controls.Add(td1);
tr.Controls.Add(td2);
tr.Controls.Add(td3);
tr.Controls.Add(td4);
tr.Controls.Add(td5);
adminlist1.Controls.Add(tr);
}
那么在VB.NET应用窗体开发时,要怎么才可以向上面一样让数据库填充类表?
不用datagridview直接连接数据源,而是自己用代码添加?求高人指导
--------------------编程问答--------------------
dim strSql1 as string="select * from 表a"
Dim MyComm As SqlDataAdapter = New SqlDataAdapter(strSql1, MyCon)
Dim MyDataset As DataSet = New DataSet
MyComm.Fill(MyDataset)
Me.GridView1.DataSource = MyDataset.Tables(0).DefaultView
Me.GridView1.DataBind()
不知道你说的是不是这个 --------------------编程问答-------------------- 那么如何用代码编辑datagridview的标头呢? --------------------编程问答-------------------- DataGridView1表头设置:
'设置列格式
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
DataGridView1.ColumnCount = 16
DataGridView1.TopLeftHeaderCell.Value = "回弹值"
DataGridView1.TopLeftHeaderCell.Style.Alignment = DataGridViewContentAlignment.MiddleRight '右侧对齐
'设置列标题
Dim i As Integer
For i = 0 To 15
DataGridView1.Columns(i).Width = 48
DataGridView1.Columns(i).Name = "测点" & (i + 1).ToString
DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.NotSortable '列排序方式(不排序)
DataGridView1.Columns(i).DefaultCellStyle.Format = "D" '单元格式“整型数字”
If i Mod 2 = 0 Then
DataGridView1.Columns(i).DefaultCellStyle.BackColor = Color.Bisque
DataGridView1.Columns(i).DefaultCellStyle.SelectionBackColor = Color.SeaGreen 'Thistle
End If
Next
End Sub
'设置行标题
Private Sub DataGridView1_RowPostPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) _
Handles DataGridView1.RowPostPaint
Using b As SolidBrush = New SolidBrush(DataGridView1.RowHeadersDefaultCellStyle.ForeColor)
e.Graphics.DrawString("测区" & (e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture), _
DataGridView1.DefaultCellStyle.Font, b, _
e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4)
End Using
End Sub
--------------------编程问答--------------------
表头名称可以在 select语句中指定,
比如:select 字段1 as 显示名1,字段2 as 显示名2 ……
补充:.NET技术 , VB.NET