0

私のasp.netフォームでは、テーブル行内にセルを追加し、それらのセル内に次のような属性を持つテキストボックスを追加します-

string residentId = (new GUID()).ToString();
string houseId  = (new GUID()).ToString();

HtmlTableRow detailRow = new HtmlTableRow();
detailRow.Attributes.Add("residentId", residentId);
detailRow.Attributes.Add("houseId", houseId);

HtmlTableCell dataCell = new HtmlTableCell();

TextBox tb = new TextBox();
tb.Attributes.Add("componentname", "tbMoveInDate");

tb.Attributes.Add("onchange", "updateMoveInDate()";

cell.Controls.Add(tb);
detailRow.Cells.Add(dataCell);

もちろん、すべて個別の ID を持つ 100 行以上の可能性があります。

私のjavascript内には、この機能があります-

function updateMoveInDate() {
    var MoveInDateEle = $("[componentname*='tbMoveInDate']");
}

この時点で、MoveInDateEle はテーブル内のすべてのテキスト ボックスのコレクションであり、

var currentRow = $("[componentname*='tbMoveInDate']").parent().parent();

すべての行を教えてくれます。しかし、私の特定の行ではありません。

使用している特定のテキスト ボックスと、そのコントロールに関連付けられている特定の居住者 ID と家 ID を取得するにはどうすればよいですか?

4

3 に答える 3

2

次のようにコードを変更しC#ます。

tb.Attributes.Add("onchange", "updateMoveInDate(this)";

そしてjs関数は次のようになります:

// obj here refers to the current textbox in the scope
// on which the on-change event had occurred...
function updateMoveInDate(obj) {
    var currentRow = $(obj).closest('tr');
}
于 2013-06-28T12:35:55.643 に答える
1

あなたができる

tb.Attributes.Add("onchange", "updateMoveInDate(this)";

function updateMoveInDate(txt) {
    var $txt = $(txt);
    var $row = $txt.closest('tr');
    var residentId = $row.attr('residentId');
    var houseId = $row.attr('houseId');
}
于 2013-06-28T12:36:03.987 に答える
0

これを試して

tb.Attributes.Add("onchange", "updateMoveInDate(this)";

コードビハインドで

    string residentId = (new GUID()).ToString();
    string houseId  = (new GUID()).ToString();

    HtmlTableRow detailRow = new HtmlTableRow();
    detailRow.Attributes.Add("residentId", residentId);
    detailRow.Attributes.Add("houseId", houseId);

    HtmlTableCell dataCell = new HtmlTableCell();

    TextBox tb = new TextBox();
    tb.Attributes.Add("componentname", "tbMoveInDate");

    tb.Attributes.Add("onchange", "updateMoveInDate(this)";

    cell.Controls.Add(tb);
    detailRow.Cells.Add(dataCell);

jQuery:

function updateMoveInDate(args) {
    var MoveInDateEle = $(args).closest('tr');

}
于 2013-06-28T12:39:05.010 に答える