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

Edit and insert form : Showing * for initial load for required fields

5 Answers 200 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prachi
Top achievements
Rank 1
Prachi asked on 09 Jul 2012, 06:11 PM
Hi,

I am using RADgrid and I am using server side required field validators.
I do not want to use template columns and so can not add span tag which shows * in red color if a field id required.

I am able to show the errormessage after the validation which is fine.
But the requirement is to let user know in the begining if the field is required by showing * mark against the field.

Is there any simpler way of doing this for gridbound columns without using template column .

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 10 Jul 2012, 05:08 AM
Hello Prachi,

One suggestion is that you can add a label dynamically to the column in edit mode. Here is the sample code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
    GridEditableItem item = e.Item as GridEditableItem;
    Label lbl = new Label();
    TextBox txt = (TextBox)item["ID"].Controls[0];
    lbl.Text = "*";
    lbl.ForeColor = System.Drawing.Color.Red;
    item["ID"].Controls.Add(lbl);
  }
}

Thanks,
Shinu.
0
Prachi
Top achievements
Rank 1
answered on 10 Jul 2012, 05:28 AM
Hello Shinu,

Thanks for the quick reply and simple solution.

Prachi
0
Prachi
Top achievements
Rank 1
answered on 02 Aug 2012, 12:54 AM
HI,

I have a problem with adding label in databound.
I have few events e.g. selectedIndexChanged that calls postback.
One it calls the postback event it removes this * added from edit/create screen.
0
Shinu
Top achievements
Rank 2
answered on 02 Aug 2012, 04:39 AM
Hello,

Try adding the label in ItemCreated event.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditableItem && e.Item.IsInEditMode)
  {
        GridEditableItem item = e.Item as GridEditableItem;
         Label lbl = new Label();
         TextBox txt = (TextBox)item["ID"].Controls[0];
         lbl.Text = "*";
         lbl.ForeColor = System.Drawing.Color.Red;
         item["ID"].Controls.Add(lbl);
   }
}

Thanks,
Shinu.
0
Prachi
Top achievements
Rank 1
answered on 02 Aug 2012, 04:46 PM
Thanks Shinu,

It works inside :

 

 

if(e.Item is GridEditFormItem && e.Item.IsInEditMode)

 

{

}

instead of

if (e.Item is GridEditableItem && e.Item.IsInEditMode)

  {

    }

Tags
Grid
Asked by
Prachi
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prachi
Top achievements
Rank 1
Share this question
or