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

InEditMode

3 Answers 27 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Kjell asked on 23 Sep 2013, 11:42 AM

Is it possible to set EmptyMessage in RadGrid1_ItemDataBound Edit Mode for a telerik:GridBoundColumn or GridDateTimeColumn?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 23 Sep 2013, 12:48 PM
Hi ,

Please try the following code snippet to set an empty message on TextBox.
1)GridBoundColumn

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("onFocus", "ClearMessage(" + txtBox1.ClientID + ");return false;");
            }
        }
   }

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

2)GridDateTimeColumn

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

C#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
     RadDatePicker picker = (RadDatePicker)edit["OrderDate"].Controls[0];
     if (picker.DateInput.DisplayText == string.Empty)
       {
          picker.DateInput.DisplayText = "Empty";
          picker.Attributes.Add("onFocus", "onfocus '"+ picker.ClientID+"'");
       }
   }

JS:
<script type="text/javascript">
    function onfocus(id) {      
        id.clear();
   }
</script>

Thanks,
Princy
0
Kjell
Top achievements
Rank 1
answered on 23 Sep 2013, 02:10 PM
Thanks, but it is not work like telerik:RadTextBox EmptyMessage.
If i save and not change the GridBoundColumn text, EmptyMessage (txtBox1.Text = "Empty") be default text when i save....
0
Princy
Top achievements
Rank 1
answered on 24 Sep 2013, 10:22 AM
Hi,

The ASP TextBox does not have a property EmptyMessage.Hence one suggestion would be to access the txtBox1.Text  in the UpdateCommand,that is,if the value is "Empty", set it as null,before entering it to DB.

Thanks,
Princy
Tags
Grid
Asked by
Kjell
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Kjell
Top achievements
Rank 1
Share this question
or