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

Adding controls to grid footer

3 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amit
Top achievements
Rank 1
Amit asked on 21 Oct 2010, 09:27 AM
Hey everyone,

I want to show a message everytime a user inserts some record,like record inserted successfully!! .Can i add controls to grid footer like label where i can show my message?..if yes how?...also is there any demo showing this scenario.plz help...

Thanks
Amit

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 21 Oct 2010, 09:38 AM
Hello Amit,


Call the following method after the data is bound in grid.

Code:
private void DisplayMessage(string text)
{
    RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:red'>{0}</span>", text)));
}

For complete code, check the demo: Automatic DataSource operations



-Shinu.
0
Amit
Top achievements
Rank 1
answered on 21 Oct 2010, 11:11 AM
hey,

its not working--
protected void Save_Click(object sender, EventArgs e)
        {
            Button Save = (Button)sender;
            GridEditFormInsertItem insertItem = (GridEditFormInsertItem)Save.NamingContainer;
            RadComboBox combo = insertItem.FindControl("RadComboBox1") as RadComboBox;
            Label lblRate = (Label)insertItem.FindControl("lblRate");
            RadNumericTextBox txtQauntityE = (RadNumericTextBox)insertItem.FindControl("txtQuantityE");
            Label lblAmount = (Label)insertItem.FindControl("lblAmount");
            HiddenField Amount = (HiddenField)insertItem.FindControl("Amount");
            if (combo.SelectedIndex > 0 && txtQauntityE.Text != null)
            {
                dtValues = (DataTable)Session["Table"];
                DataRow drValues = dtValues.NewRow();
                drValues["Items"] = combo.SelectedItem.Text;
                drValues["Rate"] = lblRate.Text;
                drValues["Quantity"] = txtQauntityE.Text;
                drValues["Amount"] = Amount.Value;
                dtValues.Rows.Add(drValues);
                dtValues.AcceptChanges();
                Session["Table"] = dtValues;
                RadGrid1.MasterTableView.IsItemInserted = false;
                RadGrid1.MasterTableView.Rebind();
                SetMessage("New Order is inserted!");
            }
            else
            {
               
            }
        }
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
            {
if (!string.IsNullOrEmpty(gridMessage))
                {
                    DisplayMessage(gridMessage);
                }
            }
        }
 private void DisplayMessage(string text)
        {
            RadGrid1.Controls.Add(new LiteralControl(string.Format("<span style='color:green'>{0}</span>", text)));
        }
 
        private void SetMessage(string message)
        {
            gridMessage = message;
        }
        private string gridMessage = null;
0
Accepted
Princy
Top achievements
Rank 2
answered on 21 Oct 2010, 12:11 PM
Hello Amit,

Since you are closing the insert form after saving the item, it will not enter into the 'If Condition' inside ItemDataBound. Thats why it is not showing the message. You can check this demo  which explains how to display the message in DataBound event or you call the function directly inside Save Button .

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