我有一個條形碼掃描器,當我掃描任何框時,該特定的「BoxID
」位於我的文本框中。所以當我點擊輸入時,它應該檢查GridView中特定的BoxID
,並且應該爲整行着色。查看下面的截圖。當文本框的值與特定的gridview列值匹配時,更改Gridview行的顏色
我用RowDataBound
函數來改變顏色,但是這個函數只能在GridView的DataBinds中運行一次。
我的RowDataBound代碼:
protected void GridView2_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// determine the value of the UnitsInStock field
string myBoxId = (DataBinder.Eval(e.Row.DataItem, "BoxID")).ToString();
if (myBoxId == TextBox1.Text)
{
e.Row.BackColor = System.Drawing.Color.Yellow;
}
}
}
此代碼是正確的,但正如我所說的它僅發生gridview的databinds。
所以,我試着撥打的RowDataBound在TextBox1_TextChanged
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
GridView2.RowDataBound += new GridViewRowEventHandler(GridView2_RowDataBound);
}
即使它did'n工作。
所以我想寫一個像RowDataBound,在textbox.textchanged內的方法。我也嘗試過,但他們已經使用了「e」,這是一個GridViewRowEventArgs
。因此,如何調用textbox.textchanged這個「E」,像「Gridview2.Row.RowType
」,而不是在ASP.NET
任何想法「e.Row.RowType
」?
我想你在尋找這個http://www.aspsnippets.com/Articles/Search-records-in-GridView-and-highlight-results-in-ASPNet-using-C-and-VBNet.aspx – 2015-10-06 05:35:04
謝謝你,但不,這只是選擇所有與文本框值有關的值,但我想顏色那個心室行,我的id是唯一的 –
你想要整行顏色? – 2015-10-06 05:38:02