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

Empty in Textbox during edit

1 Answer 22 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erin
Top achievements
Rank 1
Erin asked on 16 Oct 2013, 12:30 PM
Hi,
how to show empty in textbox during edit mode if that column doesnot contain any value.

Thanks,
Erin. 

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 16 Oct 2013, 12:37 PM
Hi Erin,

Please try the following code snippet to set Empty in Textbox .

ASPX:
<telerik:GridBoundColumn DataField="OrderDate" HeaderText="OrderDate" UniqueName="OrderDate" />

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["OrderDate"].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,
Princy
Tags
Grid
Asked by
Erin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Share this question
or