我有一个gridview,其中我动态添加了几个文本框,如下面的代码所示:
protected void getDateControls()
{
foreach (GridViewRow grow in gdView.Rows)
{
System.Web.UI.WebControls.TextBox txtFrom = new System.Web.UI.WebControls.TextBox();
txtFrom.ID = "txtFrom";
txtFrom.Width = 70;
txtFrom.AutoPostBack = true;
txtFrom.TextChanged += new System.EventHandler(this.txtFrom_Changed);
grow.Cells[5].Controls.Add(txtFrom);
System.Web.UI.WebControls.TextBox txtTo = new System.Web.UI.WebControls.TextBox();
txtTo.ID = "txtTo";
txtTo.Width = 70;
txtTo.AutoPostBack = true;
txtTo.TextChanged += new System.EventHandler(this.txtTo_Changed);
grow.Cells[6].Controls.Add(txtTo);
}
}
我还有jquery函数,当这些文本框获得焦点时会触发datepicker,如下所示:
<script type="text/javascript">
$(document).ready(function() {
$(document).on("focus", "input[id*='txtFrom']", function() {
$(this).datepicker({
//appendText:'mm/dd/yyyy',
//showOn: 'both',
//buttonText: '..',
dateFormat: 'dd/mm/yy',
//numberOfMonths:2,
changeMonth: true,
changeYear: true,
minDate: new Date(2017, 4, 1),
maxDate: new Date(2025, 3, 31)
});
});
$(document).on("focus", "input[id*='txtTo']", function() { $(this).datepicker({
//appendText:'mm/dd/yyyy',
//showOn: 'both',
//buttonText: '..',
dateFormat: 'dd/mm/yy',
//numberOfMonths:2,
changeMonth: true,
changeYear: true,
minDate: new Date(2017, 4, 1),
maxDate: new Date(2025, 3, 31)
});
});
});
现在我想得到一排&amp;文本框具有焦点的单元格的col索引。怎么做?请帮忙。
感谢大家的期待。