[英]Can't retrieve value from template field
我試圖從我的templatefield中獲取我在gridview中的ID的值。
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("cr_Id") %>'></asp:Label>
</ItemTemplate>
我需要檢索此ID進行更新。 以下是來自aspx.cs的代碼
GridView myGrid = (GridView)sender; // the gridview
Label lblProdId = (Label)myGrid.FindControl("lblID");
string colID = lblProdId.ToString();
BLLCredentials updateID = new BLLCredentials();
int ds;
ds = updateID.updStatus(colID, 1);
gv_CredentialsList.EditIndex = -1;
Bind();
sendEmail();
錯誤是
你調用的對象是空的。
說明:執行當前Web請求期間發生未處理的異常。
請查看堆棧跟蹤,以獲取有關錯誤及其在代碼中起源的更多信息。
異常詳細信息:System.NullReferenceException:對象引用未設置為對象的實例。
您可以在GridView Itemtemplate中找到一個控件,例如
Label lblProdId = (Label )myGrid.Rows[0].Cells[0].FindControl("lblID");
行[輸入行索引]和單元格[輸入單元格索引]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.