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

[Solved] stop the databinding process in radgrid when switching to insert mode

5 Answers 415 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Buffet
Top achievements
Rank 1
Buffet asked on 19 May 2008, 09:52 AM

Hi

How do I stop the databinding process in my grid when switching to insert mode?

My RadGrid has 1 ItemTemplate column and 1 EditFormSettings FormTemplate column. I therefore only have standard controls in the templates with usual data binding expressions eg <%# Bind(" StoreName") %>

The idea is to use RadGrid similarly to asp:FormView in that I only show/edit/insert 1 record at a time in a Form format as opposed to rows/tabular format.

When the user selects an option (eg store name) from an external dropdownlist it triggers the grid to retrieve  the store details from a datasource. 

When the user clicks Edit command button, the grid switches to Edit form.

I have an Insert LinkButton that sits outside of the grid which turns the form to an empty data entry form for insertion. Its event handler below:

protected void imgAddStore_Clicked(object sender, EventArgs e) {
    gridDetailsStore.MasterTableView.IsItemInserted = true;
    gridDetailsStore.DataBind();
}

After messing around, I found that I had to call DataBind() (per above) on the grid to make the Insert form appears in place of the View form.

However, this also goes through  the Select Command and reloads the record.

Because I hide the item template column to only show the Insert form when in Insert mode, I do not want the Select Command to execute because it's redundant when I am inserting a new record.

How do i stop the Select Command to execute?

Thanks for your help.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 May 2008, 10:33 AM
Hi Buffet,

Go through the following demo link.
Form template edit form

Also try binding the Grid in the NeedDataSource event. Go through the following demo link for getting more information about AdvanceDataBinding techniques.

Shinu.

0
Buffet
Top achievements
Rank 1
answered on 19 May 2008, 12:12 PM
Hi Shinu

Thanks for your reply. I have gone through the references you referred to.

Back in my event handler (below) of the LinkButton that resides "outside" of the grid (ie it is NOT a part of CommandItemTemplate element), I had to call DataBind() on the grid after setting the IsItemInserted to "true" to make the Insert form show up.

If the Select command is always executed by the grid once DataBind() is invoked hence we cannot top it then alternatively, can I make the Insert form show up without calling DataBind() in my event handler of the LinkButton?

Or, what other technique can I use to make it show up that does not make an extra Select to the database when the form is switching?


protected
void imgAddStore_Clicked(object sender, EventArgs e) {
    gridDetailsStore.MasterTableView.IsItemInserted = true;
    gridDetailsStore.DataBind();
}

0
Buffet
Top achievements
Rank 1
answered on 19 May 2008, 12:24 PM
Hi Shinu

So that I can explain myself better.

In the demo http://www.telerik.com/demos/aspnet/Grid/Examples/DataEditing/TemplateFormUpdate/DefaultCS.aspx, when I click Add New Record, I only want to show the Insert form, not any other row below it.  

So I hide all other rows as the documentation shows (see Hide all rows on insert and displaying the edit form only ms-help://telerik.aspnetajax.radcontrols.2008.Q1/telerik.aspnetajax.radgrid.2008.Q1/hide-all-rows-on-inser-tand-display-edit-form.html

Because I only "hide" the rows, the grid still make a "Select" trip to the database to retrieve the records. That's is what I don't want happen because it's redundant and make the insert slow.

Can we do it?

Thanks

0
Princy
Top achievements
Rank 2
answered on 20 May 2008, 06:58 AM
Hi Buffet,

Try Rebinding the Grid instead of doing DataBind().

protected void imgAddStore_Clicked(object sender, EventArgs e)  
 {  
    gridDetailsStore.MasterTableView.IsItemInserted = true;  
    gridDetailsStore.Rebind();  

Princy.
0
Buffet
Top achievements
Rank 1
answered on 20 May 2008, 02:15 PM
Hi Princy

Rebind() does not work. The grid does not change at all.

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