C# 向GridViewRow添加文本行和链接按钮
好的,到目前为止我有这个代码:C# 向GridViewRow添加文本行和链接按钮,c#,asp.net,C#,Asp.net,好的,到目前为止我有这个代码: for (int i = 0; i < fajlovi.Length ; i++) { string filename = fajlovi[i]; string link = Server.MapPath("~/upload" + "//" + Page.User.Identity.Name) + fajlovi[i]; LinkButton but
for (int i = 0; i < fajlovi.Length ; i++)
{
string filename = fajlovi[i];
string link = Server.MapPath("~/upload" + "//" + Page.User.Identity.Name) + fajlovi[i];
LinkButton button = new LinkButton();
button.Text = "Download";
button.PostBackUrl = link;
GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal);
}
for(int i=0;i
现在我需要的是将字符串文件名和linkbutton按钮添加到GridView中的一行。我知道我需要创建一个GridViewRow,然后将该行添加到GridView中,但我不知道如何将元素添加到该行中
有人知道如何使用它吗?必须将元素添加到TableCell,而TableCell又必须添加到GridViewRow:
// Filename
string filename = "...";
Label lbl_filename = new Label();
lbl_filename.Text = filename;
// ...
// Button
LinkButton button = new LinkButton();
button.Text = "Download";
// ...
GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.ColumnSpan = some_columnspan;
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Controls.Add(lbl_filename); // add control
cell.Controls.Add(button); // add control
row.Cells.Add(cell);
必须将元素添加到TableCell,TableCell又必须添加到GridViewRow:
// Filename
string filename = "...";
Label lbl_filename = new Label();
lbl_filename.Text = filename;
// ...
// Button
LinkButton button = new LinkButton();
button.Text = "Download";
// ...
GridViewRow row = new GridViewRow(i, i, DataControlRowType.DataRow, DataControlRowState.Normal);
TableCell cell = new TableCell();
cell.ColumnSpan = some_columnspan;
cell.HorizontalAlign = HorizontalAlign.Left;
cell.Controls.Add(lbl_filename); // add control
cell.Controls.Add(button); // add control
row.Cells.Add(cell);