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

How to fire the add new record event when we are using CommandItemDisplay="TopAndBottom" in the radGrid

3 Answers 937 Views
Grid
This is a migrated thread and some comments may be shown as answers.
sirisha
Top achievements
Rank 1
sirisha asked on 18 Sep 2008, 08:20 AM
Hi,
   im using

CommandItemDisplay

="TopAndBottom"

 option to allow automatic insertion of records in the grid. When i place this property "Add New Record" link is displayed in the top and bottom of the grid.
and in the

oninsertcommand

="RadGroupsGrid_InsertCommand"

i wrote the code as follows:

protected void RadGroupsGrid_InsertCommand(object source, GridCommandEventArgs e)

{

GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;

string GroupName = (insertItem["Group_Name"].Controls[0] as TextBox).Text;

string GroupDesc = (insertItem["Group_desc"].Controls[0] as TextBox).Text;

SqlCommand cmdNewGroup = new SqlCommand();

cmdNewGroup.Connection = con;

con.Open();

cmdNewGroup.CommandType =

CommandType.StoredProcedure;

cmdNewGroup.CommandText =

"Groups_Insert";

cmdNewGroup.Parameters.AddWithValue(

"@Group_Name", GroupName);

cmdNewGroup.Parameters.AddWithValue(

"@Group_desc", GroupDesc);

cmdNewGroup.Parameters.AddWithValue(

"@Case_Id", 3);

cmdNewGroup.ExecuteNonQuery();

}

But when i click the "Add New Record" link the event is not gettign fired and the pop-up for inserting new record is not getting displayed.
Do we need to create the controls for the insert pop-up or will it generate automatically like Edit pop-up?
Can u please tell me how to open a pop-up to insert new record automatically.

Thank you,
sirisha

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 18 Sep 2008, 09:21 AM
Hello Sirisha,

Setting the EditMode property  to PopUp should generate a PopUp form for both Edit and Insert modes.
aspx:
 <MasterTableView DataSourceID="SqlDataSource1" CommandItemDisplay="Top EditMode="PopUp"  > 

The InsertCommand event will fire only when you click on the InsertButton in the form. If you want a server-side event to fire on clicking the AddNewRecord button, you can check for CommandName="InitInsert" in the ItemCommand event of the grid as shown below.
cs:
 protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
         if (e.CommandName == "InitInsert")  
        { 
         
        } 
    } 

Princy.
0
girish
Top achievements
Rank 1
answered on 16 Dec 2010, 05:33 AM
Hi,
 I want to set some default values to text box when i am clicking on Add new Record button.

i put all text boxes in Item template

0
Shinu
Top achievements
Rank 2
answered on 16 Dec 2010, 11:24 AM
Hello Girish,

 You can access the TextBox in EditItemTemplate using the findControl method and then set the default value.  Here is the sample code.  

C#:
protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
       {
           GridEditFormInsertItem item = (GridEditFormInsertItem)e.Item;
           TextBox txtBox = (TextBox)item.FindControl("TextBox1");
           txtBox.Text = "YourText";
       }  
   }

Shinu.
Tags
Grid
Asked by
sirisha
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
girish
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or