我将尝试通过编程的方式向
因此,在aspx中,它看起来像这样:
GridView
添加一个ButtonField
。因此,在aspx中,它看起来像这样:
<asp:ButtonField ButtonType="Image"
CommandName="buttonClicked"
ImageUrl="~/checkdailyinventory.bmp" />
这是我在C#中尝试复制的内容。
GridView genGridView = new GridView();
//Where the xml gets bonded to the data grind
XmlDataSource xds = new XmlDataSource();
xds.Data = xml;
xds.DataBind();
xds.EnableCaching = false;
genGridView.DataSource = xds;
genGridView.DataBind();
// formating is done here
ButtonField test3 = new ButtonField();
test3.ButtonType = ButtonType.Image;
test3.CommandName = "buttonClicked";
test3.ImageUrl = "~/checkdailyinventory.bmp";
genGridView.Columns.Add(test3);
这不会创建任何新的列。
希望能获得任何帮助。
更新进度
我已经成功创建了列,但它们是第一列,而不是最后一列。为了做到这一点,我必须在数据绑定之前放置按钮创建和添加列。
GridView genGridView = new GridView();
//Where the xml gets bonded to the data grind
XmlDataSource xds = new XmlDataSource();
xds.Data = xml;
xds.DataBind();
xds.EnableCaching = false;
//Set the rowdatabound before binding. This will allow the correct function to be called.
genGridView.RowDataBound += new GridViewRowEventHandler(inventoryGridView_RowDataBound);
genGridView.RowCommand += new GridViewCommandEventHandler(inventoryGridView_RowCommand);
ButtonField test3 = new ButtonField();
test3.ButtonType = ButtonType.Image;
test3.CommandName = "buttonClicked";
test3.ImageUrl = "checkdailyinventory.bmp";
genGridView.Columns.Add(test3);
genGridView.DataSource = xds;
genGridView.DataBind();
而实际上,你的html可能是这个样子:
所以它不能正常工作。 请确保使用正确的html代码。
<td><input type="image" src="checkdailyinventory.bmp" onclick="javascript:__doPostBack('inventoryGridView','buttonClicked$2')" style="border-width:0px;" /></..>
然而实际上,它看起来是这样的:
<td><input type="image" src="checkdailyinventory.bmp" onclick="javascript:__doPostBack('ctl03','buttonClicked$2')" style="border-width:0px;" /></..>
因此,我需要找出如何将ct103
替换为inventoryGridView