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

label Message

3 Answers 29 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sem
Top achievements
Rank 1
sem asked on 28 Jul 2012, 06:26 AM
Hi,

in the (RadGrid1_InsertCommand) event i'm checking the data inserted before inserting it in Database
and if it didn't match certain condition i want a message to appear to the user to tell him that
i tried to set a label with the message but it didn't work
it seems the grid events don't set values of outside controls
what to do ?

Thanks

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Jul 2012, 04:33 AM
Hello,

One suggestion is that you can add a label in ItemCreated event as shown below.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
   if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
   {
     GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
     Label lbl = new Label();
    lbl.Text = "*";
    item["UniqueName"].Controls.Add(lbl);
    }
}

Thanks,
Shinu.
0
sem
Top achievements
Rank 1
answered on 30 Jul 2012, 04:41 AM
thanks for replying
but i have a question :
how to control the visibility of this label i added to the grid ?

thanks
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Jul 2012, 09:20 AM
Hello,

Here is the sample code that I tried to change the visibility of the label by attaching the TextChanged event in insert mode.
C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
 {
    GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
    TextBox txt = (TextBox)item["UniqueName"].Controls[0];
    txt.AutoPostBack = true;
    txt.TextChanged += new EventHandler(txt_TextChanged);
    Label lbl = new Label();
    lbl.ID = "Label1";
    lbl.Text = "*";
    item["UniqueName"].Controls.Add(lbl);
 }
}
void txt_TextChanged(object sender, EventArgs e)
{
    TextBox txt = (TextBox)sender;
    GridEditFormInsertItem item = (GridEditFormInsertItem)txt.NamingContainer;
    Label lbl = (Label)item.FindControl("Label1");
    lbl.Visible = false;
}

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