我需要從RowCommand事件中獲取單元格的值,但該值不在GridView的PrimaryKeyNames參數中。在RowCommand中獲取GridView單元格的值
目前我有:
if (e.CommandName == "DeleteBanner")
{
GridViewRow row = gvCurrentPubBanner.SelectedRow;
string BannerName = row.Cells[1].Text;
這不起作用(索引超出範圍錯誤的),我也試着:
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvCurrentBanners.Rows[index];
這不起作用,無論是作爲CommandArgument (橫幅ID)不是行ID。
解決'asp:TemplateField - ItemTemplate'? – Kiquenet
參考@Chưabiết答案爲Itemtemplate字段。 –