问题描述
我有一个gridview和一个文本框
我想做的就是在每个onkeyup上更改gridview内容的搜索文本框
我做了这部分,虽然
问题是当页面回发时,对文本框的关注丢失了.
当我在代码后面以textbox.focus()的形式编写代码时,文本内的所有元素都将突出显示,而当我再次在textbox Disapper中键入文本时.
有没有办法专注于文本框并取消突出显示?
请帮忙!
对不起,我的英语不好
aspx
i have a gridview and a textbox
all i wanna do is a searching textbox that on each onkeyup the gridview contents changed
i did this part although
the problem is when the page postback, the focus on textbox lost.
And when i write code in code-behind as textbox.focus(), all the element inside the text are highlightened, and when i type again the text inside textbox disapper.
is there a way to focus on textbox and unhighlightened it?
please help!
sorry for my poor english
aspx
function __doPostBack(eventTarget, eventArgument)
{
document.Form1.__EVENTTARGET.value = eventTarget;
document.Form1.__EVENTARGUMENT.value = eventArgument;
document.Form1.submit();
}
<asp:TextBox ID="txtLike" runat="server" Width="240px"
AutoPostBack="True" onkeyup="javascript:__doPostBack('txtLike','')"
ontextchanged="txtLike_TextChanged"></asp:TextBox>
代码隐藏
code-behind
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Form["__EVENTTARGET"] == "txtLike")
{
txtLike_TextChanged(this,new EventArgs());
}
}
protected void txtLike_TextChanged(object sender, EventArgs e)
{
GridView1.DataBind();
//SetFocus(txtLike) or txtLike.Focus();
}
推荐答案
//for serching gridview on keyup
function Filter(Obj) {
var grid = document.getElementById('cntPlcHolder_gvDisplay');
var terms = Obj.value.toUpperCase();
var cellNr = 0; //your grid cellindex like name
var ele;
for (var r = 1; r < grid.rows.length; r++) {
ele = grid.rows[r].cells[cellNr].innerHTML.replace(/<[^>]+>/g, "");
if (ele.toUpperCase().indexOf(terms) >= 0)
grid.rows[r].style.display = '';
else grid.rows[r].style.display = 'none';
}
}
//调用函数
< input type =''text''onkeyup =''Filter(this);''id ="txtSearch" class ="SmallTextBox" runat ="server"/>
祝你好运
//calling of function
<input type=''text'' onkeyup=''Filter(this);'' id="txtSearch" class="SmallTextBox" runat="server" />
Best Luck
这篇关于搜索gridview的文本框; GridView中文本框内容的onkeypress更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!