我正在制作一个表格,我在其中添加动态超链接。
唯一的问题是它只显示在最后一行。我在论坛上环顾四周,但找不到任何接近这个问题的东西。
int index = 0;
int index2 = 0;
string Error = "";
TableCell TCell = new TableCell();
TableRow TRij = new TableRow();
OleDbConnection Conn = new OleDbConnection(System.Configuration.ConfigurationManager.ConnectionStrings["Database"].ConnectionString);
try
{
OleDbCommand SqlQuerry = new OleDbCommand("SELECT naam, omschrijving,prijs,Productnummer FROM Producten WHERE categorie = 3 ", Conn);
Conn.Open();
OleDbDataAdapter reader = new OleDbDataAdapter(SqlQuerry);
DataTable DataBase = new DataTable();
DataColumnCollection column = DataBase.Columns;
reader.Fill(DataBase);
HyperLink Test = new HyperLink();
int[] Nummers = new int[DataBase.Rows.Count];
DataBase.Columns.Add("meer info");
DataBase.Columns.Add("voeg toe aan winkelwagen");
foreach (DataColumn coll in DataBase.Columns)
{
if (coll.Caption == "Productnummer") {
}
else
{
TCell = new TableCell();
TCell.Text = coll.Caption;
TRij.Cells.Add(TCell);
}
}
TBProducten.Rows.Add(TRij);
while (DataBase.Rows.Count > index)
{
TRij = new TableRow();
TBProducten.Rows.Add(TRij);
while (index2 < DataBase.Columns.Count - 3){
TCell = new TableCell();
TCell.Text = DataBase.Rows[index].ItemArray[index2].ToString();
TRij.Cells.Add(TCell);
index2++;
}
Test.ID = index.ToString();
Test.NavigateUrl = "~/Product.aspx?q=" + DataBase.Rows[index].ItemArray[index2].ToString();
Test.Text = "Klik hier voor meer informatie";
TCell = new TableCell();
TCell.Controls.Add(Test);
TRij.Cells.Add(TCell);
TBProducten.Rows.Add(TRij);
//{
// TCell = new TableCell();
// TCell.Text = reader.GetValue(index2).ToString();
// TRij.Cells.Add(TCell);
//}
index2 = 0;
index++;
}
}
catch (Exception E)
{
Error = E.Message.ToString();
lblError.Text = Error;
}
finally
{
Conn.Close();
}
答案 0 :(得分:0)
问题是在循环中我没有宣布
HyperLink Test = new HyperLink();
这就是为什么只有一个。