我有一个javascript,在我的gridview上添加了一个搜索框。它加载页面:
<script type="text/javascript">
$(document).ready(function () {
$('<thead></thead>').prependTo('table#ctl00_MainContent_GVOPL').append($('table#ctl00_MainContent_GVOPL tr:first'));
$('table#ctl00_MainContent_GVOPL tbody tr').quicksearch({
reset: true,
resetClass: "resetButton",
resetLabel: "Zurücksetzen",
position: 'before',
attached: 'table#ctl00_MainContent_GVOPL',
stripeRowClass: ['odd', 'even']
});
$(".qs_input").focus();
});
使用计时器我更新gridview。第一次更新后,搜索框消失。想法是添加javascript以在计时器中执行。但是我该怎么做呢?
计时器:
<asp:Timer ID="Timer1" runat="server" Interval="5000" ontick="Timer1_Tick" />
protected void Timer1_Tick(object sender, EventArgs e)
{
...build my gridview...
}
答案 0 :(得分:1)
你需要在PostBack
之后再次调用搜索框的绑定在函数中包装您的Javascript
<script type="text/javascript">
$(document).ready(function () {
bindSearchBox();
});
function bindSearchBox() {
$('<thead></thead>').prependTo('table#ctl00_MainContent_GVOPL').append($('table#ctl00_MainContent_GVOPL tr:first'));
.....
}
</script>
然后在Timer Tick中重新加载GridView时从代码中调用该函数。
protected void Timer1_Tick(object sender, EventArgs e)
{
//...build my gridview...
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "bindBox", "bindSearchBox()", true);
}