今天编程时我想实现的效果是 从数据库动态提取数据,提交到动态生成的表单中,其中有一列需要完成单击事件,所以我想用生成的hyerlink完成链接事件。请问还需添加哪些代码才可以实现,代码如下:
protected void Page_Load(object sender, EventArgs e)
{ string str = ConfigurationManager.ConnectionStrings["Connstr3"].ToString();
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
string s = "select * from newa ";
OleDbCommand com = new OleDbCommand(s, conn);
da.SelectCommand = new OleDbCommand(s, conn);
OleDbCommandBuilder scb = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
OleDbDataReader dr = com.ExecuteReader();
dr .Read ();
if (dr.HasRows)
{
for (int j=0, i = 0; i <= ds.Tables[0].Rows.Count - 1; i++,j ++)
{
string[] num=new string [50];string []a=new string [50];string []b=new string [50];
num [i ]=ds .Tables [0].Rows [i ][0].ToString ();
a [i ]=ds .Tables [0].Rows [i ][1].ToString ();
b[i] = ds.Tables[0].Rows[i][2].ToString();
for (int m = 0; m <=ds.Tables[0].Rows.Count;m ++ )
{
TableRow row = new TableRow();
TableCell id = new TableCell();
TableCell cname = new TableCell();
TableCell crename = new TableCell();
id.Text = num[i];
crename.Text =b [i ];
System .Web .UI .WebControls .HyperLink l = new HyperLink();
l.Text = a[i];
cname.Controls.Add(l );
row.Cells.Add(id );
row.Cells.Add(cname );
row.Cells.Add(crename );
Table1.Rows.Add(row );
}
}
} conn.Close();
}
调试结果如下:
protected void Page_Load(object sender, EventArgs e)
{ string str = ConfigurationManager.ConnectionStrings["Connstr3"].ToString();
OleDbConnection conn = new OleDbConnection(str);
conn.Open();
OleDbDataAdapter da = new OleDbDataAdapter();
string s = "select * from newa ";
OleDbCommand com = new OleDbCommand(s, conn);
da.SelectCommand = new OleDbCommand(s, conn);
OleDbCommandBuilder scb = new OleDbCommandBuilder(da);
DataSet ds = new DataSet();
da.Fill(ds);
OleDbDataReader dr = com.ExecuteReader();
dr .Read ();
if (dr.HasRows)
{
for (int j=0, i = 0; i <= ds.Tables[0].Rows.Count - 1; i++,j ++)
{
string[] num=new string [50];string []a=new string [50];string []b=new string [50];
num [i ]=ds .Tables [0].Rows [i ][0].ToString ();
a [i ]=ds .Tables [0].Rows [i ][1].ToString ();
b[i] = ds.Tables[0].Rows[i][2].ToString();
for (int m = 0; m <=ds.Tables[0].Rows.Count;m ++ )
{
TableRow row = new TableRow();
TableCell id = new TableCell();
TableCell cname = new TableCell();
TableCell crename = new TableCell();
id.Text = num[i];
crename.Text =b [i ];
System .Web .UI .WebControls .HyperLink l = new HyperLink();
l.Text = a[i];
cname.Controls.Add(l );
row.Cells.Add(id );
row.Cells.Add(cname );
row.Cells.Add(crename );
Table1.Rows.Add(row );
}
}
} conn.Close();
}
调试结果如下:
解决方案 »
- 急~如何从datagridview中把被选中CheckBox的多行存入到LIST中?
- winform中dataGridView有一个列是float类型数值问题
- 关于winfrom DatagridView CheckBox列勾选状态
- C#中多线程同时读写一个文件的问题
- [跪求]C#中写Web时,如何打开一个文件夹选择框,选择其中一个文件夹后,并返回文件夹路径
- 问题描述在最后一行- 关于委托列表清空的问题
- 求winform模范QQ图文混合发送的写入及读取的代码
- 如何让程序在计算机启动时自动运行一事件方法?
- SQL SERVER 存储大文本出错?HELP!!!
- 怎样获取表中的数据信息呀
- 关于Socket异步通信的小问题
- 能自动触发reportViewer工具栏上的打印按钮吗?
l.onClick+=