Tilføje ekstra kolonne med knapper til eksisterende DataTable
HejJeg ønsker at tilføje en kolonne til min datatable, Denne kolonne skal indeholde knapper til at redigere, slette og se en datarække. Mit problem er, at jeg er i tvivl hvordan jeg tilføjer denne ekstra kolonne med knapper.
Jeg har allerede understående kode :
private void BuildImageButton(TableRow row, string cArg, string type)
{
ImageButton ibn = new ImageButton();
ibn.Command += new CommandEventHandler(this.btn_Click);
if (type.Equals("view"))
{
ibn.ImageUrl = "../Images/viewButton.gif";
ibn.AlternateText="view Account";
ibn.Attributes.Add("OnMouseOver", "this.src='../Images/viewButton_hover.gif'");
ibn.Attributes.Add("OnMouseOut", "this.src='../Images/viewButton.gif'");
}
else if (type.Equals("edit"))
{
ibn.ImageUrl = "../Images/editButton.gif";
ibn.AlternateText="edit Acount";
ibn.Attributes.Add("OnMouseOver", "this.src='../Images/editButton_hover.gif'");
ibn.Attributes.Add("OnMouseOut", "this.src='../Images/editButton.gif'");
}
else
{
ibn.ImageUrl = "../Images/deleteButton.gif";
ibn.AlternateText="delete Account";
ibn.Attributes.Add("OnMouseOver", "this.src='../Images/deleteButton_hover.gif'");
ibn.Attributes.Add("OnMouseOut", "this.src='../Images/deleteButton.gif'");
}
ibn.CommandArgument = cArg;
TableCell cell = new TableCell();
cell.Controls.Add(ibn);
cell.HorizontalAlign = HorizontalAlign.Center;
cell.VerticalAlign = VerticalAlign.Middle;
row.Cells.Add(cell);
}
private void Page_Load(object sender, System.EventArgs e)
{
DataTable dt = company.GetCompany();
dt.Columns.Add("Funktioner");
foreach(DataRow dr in dt.Rows)
{
BuildImageButton(row, "CompanyView.aspx?CID=" + dr["CompanyID"].ToString(),"view");
BuildImageButton(row, "CompanyUpdate.aspx?CID=" + dr["CompanyID"].ToString(),"edit");
BuildImageButton(row, "CompanyRemove.aspx?CID=" + dr["CompanyID"].ToString(),"delete");
}
}