Hi All,
I have a requirement of adding text in filter box
i.e adding "Search" keyword in all filter box in grid .
when the user click on textbox of the filter then the text should be empty to enter text to search.
Please advice.
I have a requirement of adding text in filter box
i.e adding "Search" keyword in all filter box in grid .
when the user click on textbox of the filter then the text should be empty to enter text to search.
Please advice.
4 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 04 Aug 2011, 01:26 PM
Hello Ram,
Try the following code snippet to achieve your requirement.
C#:
Javascript:
Thanks,
Princy.
Try the following code snippet to achieve your requirement.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) { if (e.Item is GridFilteringItem) { GridFilteringItem item = (GridFilteringItem)e.Item; TextBox txtBox1 = (TextBox)item["OrderID"].Controls[0]; txtBox1.Attributes.Add("onBlur", "return SetMessage(" + txtBox1.ClientID + ");"); txtBox1.Attributes.Add("onFocus", "return ClearMessage(" + txtBox1.ClientID + ");"); } }function ClearMessage(obj) { if (obj.value == "Search") obj.value = ""; } function SetMessage(obj) { if (obj.value == "") obj.value = "Search"; }Thanks,
Princy.
0
ramkumar
Top achievements
Rank 1
answered on 05 Aug 2011, 03:27 AM
Thanks for your reply.
Still I cound not see "Search" keyword in the page load .. when I click on the Grid i can see the "Search".
Thanks.
Still I cound not see "Search" keyword in the page load .. when I click on the Grid i can see the "Search".
Thanks.
0
Princy
Top achievements
Rank 2
answered on 05 Aug 2011, 05:23 AM
Hello Ram,
Here is the sample code that I tried to show the "Search" keyword when page loads.
C#:
Thanks,
Princy.
Here is the sample code that I tried to show the "Search" keyword when page loads.
C#:
protected void RadGrid1_PreRender(object sender, EventArgs e){ GridFilteringItem fitem=(GridFilteringItem)RadGrid1.MasterTableView.GetItems(GridItemType.FilteringItem)[0]; TextBox txt = fitem["ColumnUniqueName"].Controls[0] as TextBox; txt.Text = "Search";}Thanks,
Princy.
0
DEBAL
Top achievements
Rank 1
answered on 24 Feb 2012, 03:40 PM
This is correct answer , but I can't able to implement your java script, but using below it is going ok , what I desired
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridFilteringItem)
{
GridFilteringItem item = (GridFilteringItem)e.Item;
TextBox filter = (TextBox)item["QuestionCode"].Controls[0];
filter.Text = "--Filter--";
filter.ToolTip = "Type here your code to do Filter";
filter.Attributes.Add("onblur", "WaterMark(this, event);");
filter.Attributes.Add("onfocus", "WaterMark(this, event);");
}
}
here is the Java Script:
var defaultText = "--Filter--";
function WaterMark(txt, evt) {
if (txt.value.length == 0 && evt.type == "blur") {
txt.style.color = "gray";
txt.value = defaultText;
}
if (txt.value == defaultText && evt.type == "focus") {
txt.style.color = "black";
txt.value = "";
}
}
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridFilteringItem)
{
GridFilteringItem item = (GridFilteringItem)e.Item;
TextBox filter = (TextBox)item["QuestionCode"].Controls[0];
filter.Text = "--Filter--";
filter.ToolTip = "Type here your code to do Filter";
filter.Attributes.Add("onblur", "WaterMark(this, event);");
filter.Attributes.Add("onfocus", "WaterMark(this, event);");
}
}
here is the Java Script:
var defaultText = "--Filter--";
function WaterMark(txt, evt) {
if (txt.value.length == 0 && evt.type == "blur") {
txt.style.color = "gray";
txt.value = defaultText;
}
if (txt.value == defaultText && evt.type == "focus") {
txt.style.color = "black";
txt.value = "";
}
}