ユーザーが新しい行を追加できるグリッド ビューがあります。行を追加すると、IDは次のように変更されます..
$('<div class=".grdLoaded">').load("GridRow.htm", function () {
// insert the html
$(_InsertionID).after($(this).html());
// now change the default id(s) that were present on GridRow.htm
// to something that represent current value(s)
$('#grdEntry').find('#grdEntry_ctl00_lblSNO').attr('id', 'SNo_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblQty').attr('id', 'Qty_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblItemName').attr('id', 'ItemName_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblProcess').attr('id', 'Prc_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblRemarks').attr('id', 'Remarks_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblColor').attr('id', 'Color_' + _insCurRowNumber + '');
$('#grdEntry').find('#grdEntry_ctl00_lblAmount').attr('id', 'Amount_' + _insCurRowNumber + '');
追加されている現在の行 ID はどこにinsCurRowNumber
あり、最初は 1、2 番目は 2 などです。問題は、このようにサーバー上のこれらのコントロールのいずれかにアクセスしようとした場合です。
((Label)grdEntry.Rows[i].FindControl("ItemName_1").Text;
またはこのようなイベント
Page.FindControl("ItemName_1")
を取得しnull reference exception
ます。問題は、サーバー側がこれらの動的に生成された ID を見つけられないことです。それが原因である場合、どうすればこれを回避できますか? それが原因ではない場合、この動作の原因は何ですか?また、これらのコントロールが値にアクセスする方法を見つけるにはどうすればよいですか?
EDIT : Steven Hunt への応答として、リクエストは投稿形式でした。キーのコレクションは次のとおりです。
Request.Form.AllKeys {string[177]} string[]
[0] "__EVENTTARGET" string
[1] "__EVENTARGUMENT" string
[2] "__LASTFOCUS" string
[3] "__VIEWSTATE" string
[4] "__EVENTVALIDATION" string
[5] "check" string
[6] "txtDueDate" string
[7] "txtTime" string
[8] "txtCustomerName" string
[9] "grdEntry$ctl01$txtQty" string
[10] "grdEntry$ctl01$txtName" string
[11] "grdEntry$ctl01$txtProcess" string
[12] "grdEntry$ctl01$txtRate" string
[13] "grdEntry$ctl01$txtRemarks" string
[14] "tags" string
[15] "grdEntry$ctl01$txtColor" string
[16] "txtRemarks" string
[17] "drpCheckedBy" string
[18] "btnSaveBooking" string
[19] "txtCurrentDue" string
[20] "a" string
[21] "txtDiscount" string
[22] "txtDiscount_TextBoxWatermarkExtender_ClientState" string
[23] "txtDiscountAmt" string
[24] "txtSrTax" string
[25] "txtTotal" string
[26] "txtAdvance" string
[27] "txtBalance" string
[28] "txtItemName" string
[29] "txtItemSubQty" string
[30] "txtNewItemName" string
[31] "txtItemCode" string
[32] "hdntemp" string
[33] "hdnItemCode" string
[34] "txtProcessCode" string
[35] "txtProcessName" string
[36] "txtCNameSearch" string
[37] "txtAddress" string
[38] "txtPhoneNo" string
[39] "grdCustomerSearch$ctl02$lnkBtnCustomerCode" string
[40] "grdCustomerSearch$ctl03$lnkBtnCustomerCode" string
[41] "grdCustomerSearch$ctl04$lnkBtnCustomerCode" string
[42] "grdCustomerSearch$ctl05$lnkBtnCustomerCode" string
[43] "grdCustomerSearch$ctl06$lnkBtnCustomerCode" string
[44] "grdCustomerSearch$ctl07$lnkBtnCustomerCode" string
[45] "grdCustomerSearch$ctl08$lnkBtnCustomerCode" string
[46] "grdCustomerSearch$ctl09$lnkBtnCustomerCode" string
[47] "grdCustomerSearch$ctl10$lnkBtnCustomerCode" string
[48] "grdCustomerSearch$ctl11$lnkBtnCustomerCode" string
[49] "grdCustomerSearch$ctl12$lnkBtnCustomerCode" string
[50] "grdCustomerSearch$ctl13$lnkBtnCustomerCode" string
[51] "grdCustomerSearch$ctl14$lnkBtnCustomerCode" string
[52] "grdCustomerSearch$ctl15$lnkBtnCustomerCode" string
[53] "grdCustomerSearch$ctl16$lnkBtnCustomerCode" string
[54] "grdCustomerSearch$ctl17$lnkBtnCustomerCode" string
[55] "grdCustomerSearch$ctl18$lnkBtnCustomerCode" string
[56] "grdCustomerSearch$ctl19$lnkBtnCustomerCode" string
[57] "grdCustomerSearch$ctl20$lnkBtnCustomerCode" string
[58] "grdCustomerSearch$ctl21$lnkBtnCustomerCode" string
[59] "grdCustomerSearch$ctl22$lnkBtnCustomerCode" string
[60] "grdCustomerSearch$ctl23$lnkBtnCustomerCode" string
[61] "grdCustomerSearch$ctl24$lnkBtnCustomerCode" string
[62] "grdCustomerSearch$ctl25$lnkBtnCustomerCode" string
[63] "grdCustomerSearch$ctl26$lnkBtnCustomerCode" string
[64] "grdCustomerSearch$ctl27$lnkBtnCustomerCode" string
[65] "grdCustomerSearch$ctl28$lnkBtnCustomerCode" string
[66] "grdCustomerSearch$ctl29$lnkBtnCustomerCode" string
[67] "grdCustomerSearch$ctl30$lnkBtnCustomerCode" string
[68] "grdCustomerSearch$ctl31$lnkBtnCustomerCode" string
[69] "grdCustomerSearch$ctl32$lnkBtnCustomerCode" string
[70] "grdCustomerSearch$ctl33$lnkBtnCustomerCode" string
[71] "grdCustomerSearch$ctl34$lnkBtnCustomerCode" string
[72] "grdCustomerSearch$ctl35$lnkBtnCustomerCode" string
[73] "grdCustomerSearch$ctl36$lnkBtnCustomerCode" string
[74] "grdCustomerSearch$ctl37$lnkBtnCustomerCode" string
[75] "grdCustomerSearch$ctl38$lnkBtnCustomerCode" string
[76] "grdCustomerSearch$ctl39$lnkBtnCustomerCode" string
[77] "grdCustomerSearch$ctl40$lnkBtnCustomerCode" string
[78] "grdCustomerSearch$ctl41$lnkBtnCustomerCode" string
[79] "grdCustomerSearch$ctl42$lnkBtnCustomerCode" string
[80] "grdCustomerSearch$ctl43$lnkBtnCustomerCode" string
[81] "grdCustomerSearch$ctl44$lnkBtnCustomerCode" string
[82] "grdCustomerSearch$ctl45$lnkBtnCustomerCode" string
[83] "grdCustomerSearch$ctl46$lnkBtnCustomerCode" string
[84] "grdCustomerSearch$ctl47$lnkBtnCustomerCode" string
[85] "grdCustomerSearch$ctl48$lnkBtnCustomerCode" string
[86] "grdCustomerSearch$ctl49$lnkBtnCustomerCode" string
[87] "grdCustomerSearch$ctl50$lnkBtnCustomerCode" string
[88] "grdCustomerSearch$ctl51$lnkBtnCustomerCode" string
[89] "grdCustomerSearch$ctl52$lnkBtnCustomerCode" string
[90] "grdCustomerSearch$ctl53$lnkBtnCustomerCode" string
[91] "grdCustomerSearch$ctl54$lnkBtnCustomerCode" string
[92] "grdCustomerSearch$ctl55$lnkBtnCustomerCode" string
[93] "grdCustomerSearch$ctl56$lnkBtnCustomerCode" string
[94] "grdCustomerSearch$ctl57$lnkBtnCustomerCode" string
[95] "grdCustomerSearch$ctl58$lnkBtnCustomerCode" string
[96] "grdCustomerSearch$ctl59$lnkBtnCustomerCode" string
[97] "grdCustomerSearch$ctl60$lnkBtnCustomerCode" string
[98] "grdCustomerSearch$ctl61$lnkBtnCustomerCode" string
[99] "grdCustomerSearch$ctl62$lnkBtnCustomerCode" string
[100] "grdCustomerSearch$ctl63$lnkBtnCustomerCode" string
[101] "grdCustomerSearch$ctl64$lnkBtnCustomerCode" string
[102] "grdCustomerSearch$ctl65$lnkBtnCustomerCode" string
[103] "grdCustomerSearch$ctl66$lnkBtnCustomerCode" string
[104] "grdCustomerSearch$ctl67$lnkBtnCustomerCode" string
[105] "grdCustomerSearch$ctl68$lnkBtnCustomerCode" string
[106] "grdCustomerSearch$ctl69$lnkBtnCustomerCode" string
[107] "grdCustomerSearch$ctl70$lnkBtnCustomerCode" string
[108] "grdCustomerSearch$ctl71$lnkBtnCustomerCode" string
[109] "grdCustomerSearch$ctl72$lnkBtnCustomerCode" string
[110] "grdCustomerSearch$ctl73$lnkBtnCustomerCode" string
[111] "grdCustomerSearch$ctl74$lnkBtnCustomerCode" string
[112] "grdCustomerSearch$ctl75$lnkBtnCustomerCode" string
[113] "grdCustomerSearch$ctl76$lnkBtnCustomerCode" string
[114] "grdCustomerSearch$ctl77$lnkBtnCustomerCode" string
[115] "grdCustomerSearch$ctl78$lnkBtnCustomerCode" string
[116] "grdCustomerSearch$ctl79$lnkBtnCustomerCode" string
[117] "grdCustomerSearch$ctl80$lnkBtnCustomerCode" string
[118] "grdCustomerSearch$ctl81$lnkBtnCustomerCode" string
[119] "grdCustomerSearch$ctl82$lnkBtnCustomerCode" string
[120] "grdCustomerSearch$ctl83$lnkBtnCustomerCode" string
[121] "grdCustomerSearch$ctl84$lnkBtnCustomerCode" string
[122] "grdCustomerSearch$ctl85$lnkBtnCustomerCode" string
[123] "grdCustomerSearch$ctl86$lnkBtnCustomerCode" string
[124] "grdCustomerSearch$ctl87$lnkBtnCustomerCode" string
[125] "grdCustomerSearch$ctl88$lnkBtnCustomerCode" string
[126] "grdCustomerSearch$ctl89$lnkBtnCustomerCode" string
[127] "grdCustomerSearch$ctl90$lnkBtnCustomerCode" string
[128] "grdCustomerSearch$ctl91$lnkBtnCustomerCode" string
[129] "txtExtraProcess1" string
[130] "txtExtraRate1" string
[131] "txtExtraProcess2" string
[132] "txtExtraRate2" string
[133] "txtWholeRemark" string
[134] "drpTitle" string
[135] "txtCName" string
[136] "txtCAddress" string
[137] "txtMobile" string
[138] "drpPriority" string
[139] "txtNewPriority" string
[140] "txtAreaLocaton" string
[141] "txtRemarks1" string
[142] "txtBDate" string
[143] "txtADate" string
[144] "hdnMAC" string
[145] "hdnEditItemId" string
[146] "hdnOption" string
[147] "hdnCustId" string
[148] "hdnUpdate" string
[149] "BranchId" string
[150] "hdnItems" string
[151] "hdnDataValues" string
[152] "hdnFirstAdd" string
[153] "hdnCustomerNameFocusOut" string
[154] "hdnCurrentValue" string
[155] "hdnCurrentGrossAmt" string
[156] "isInEditMode" string
[157] "hdnDefaultItem" string
[158] "hdnDefaultProcess" string
[159] "hdnDefaultItemProcessRate" string
[160] "hdnTaxBefore" string
[161] "hdnAllDiscount" string
[162] "hdnAllTax" string
[163] "hdnUrgentRateApplied" string
[164] "hdnAllDiscountFocusOut" string
[165] "isNetAmountInDecimal" string
[166] "hdnRecompTax" string
[167] "hdnRecompDiscount" string
[168] "hdnCustCode" string
[169] "hdnTaxAmtRecomp" string
[170] "hdnDisAmtRecomp" string
[171] "hdnBalance" string
[172] "hdnTotal" string
[173] "hdnDiscountValue" string
[174] "hdnGrdRowCount" string
[175] "hdnAllGridData" string
[176] "hiddenInputToUpdateATBuffer_CommonToolkitScripts" string
グリッドのヘッダーのgrdEntry$ctl01$txtQty
データ (行のデータではなく、 の値) 以外は何も含まれていません。それでも、すべての変数を一時配列に格納し、サーバーに渡しました。 、仕事が終わりました!
でも努力してくれてありがとう。