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

another question about RadGrid auto insert

2 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
qunwei
Top achievements
Rank 1
qunwei asked on 30 Sep 2008, 07:55 PM
In the demo of RadGrid for ASP.NET AJAX, there is Insert/Update/Delete - automatic operations, so user can do insert/update/delete without writing any code behind. 
In the demo, there are two "Add new record" buttons for user to click and add a new record. Is there any way that we can get rid of these 2 buttons, so that when the page is loaded, there is a blank row automaticly generated for user to type in his new record? And, after he inserts this record, another blank row generated for him to type in another record?
Thanks a lot.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 01 Oct 2008, 04:26 AM
Hi,

Inorder to hide the insert buttons for the GridCommandItems you can try out the following code.
cs:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        foreach (GridCommandItem cmditm in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)) 
        { 
            Button btn1 = (Button)cmditm.FindControl("AddNewRecordButton"); 
            btn1.Visible = false
            //To disable the LinkButton 
            LinkButton lnkBtn1 = (LinkButton)cmditm.FindControl("InitInsertButton"); 
            lnkBtn1.Visible = false
        } 
    } 

Check out the code snippet below to remove the CommandItem rows and also put the row in InsertMode always.
cs:
  protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        //To hide the command item rows 
        RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None; 
        //to display an insert row always 
        RadGrid1.MasterTableView.IsItemInserted = true
        RadGrid1.Rebind(); 
    } 

Thanks
Princy.
0
qunwei
Top achievements
Rank 1
answered on 02 Oct 2008, 03:00 PM
Hi, Princy,
Thank you very much. The solution you provided works!
Here is my practice, for the good of other progammers:
I added the following and everything is fine:

protected void Page_PreRender(object sender, System.EventArgs e)

{

radGridMailingList.MasterTableView.CommandItemDisplay =

GridCommandItemDisplay.None;

radGridMailingList.MasterTableView.IsItemInserted =

true;

radGridMailingList.MasterTableView.Rebind();

}

So I guess the RadGrid1_PreRender in your code snippet should be Page_PreRender. I didn't use your first code snippet since for some reason the insert button simply goes away once I added the previous code.


One more question: how can I add validation? Because there is always a blank row at the top, if I use RequiredFieldValidator, user have to type something into that blank row for him to navigate to next page...

Tags
Grid
Asked by
qunwei
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
qunwei
Top achievements
Rank 1
Share this question
or