This is a migrated thread and some comments may be shown as answers.

textbox show empty text in editmode

1 Answer 11 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Dawson
Top achievements
Rank 1
Dawson asked on 02 Dec 2013, 02:30 PM
Hi,
How can i make a textbox show empty text in editmode if the column value is empty for that row and on focusing the textbox the empty text should dissapear

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 02 Dec 2013, 02:38 PM
Hi Dawson,

Please try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
    if (e.Item is GridEditableItem && e.Item.IsInEditMode)
    {
        GridEditableItem edit = (GridEditableItem)e.Item;
        TextBox txtBox1 = (TextBox)edit["UniqueColumnName"].Controls[0];
        if (txtBox1.Text == "")
        {               
            txtBox1.Text = "Empty";                    
            txtBox1.Attributes.Add("onBlur", "SetMessage(" + txtBox1.ClientID + ");return false;");               
            txtBox1.Attributes.Add("onFocus", "ClearMessage(" + txtBox1.ClientID + ");return false;");
        }
    }
}

JS:
<script type="text/javascript">
    function ClearMessage(obj) {
        if (obj.value == "Empty")
            obj.value = "";
    }
    function SetMessage(obj) {
        if (obj.value == "") {
            obj.value = "Empty";
        }
    }  
</script>

Thanks,
Shinu
Tags
Grid
Asked by
Dawson
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or