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

Rad Grid edit form insert form

14 Answers 722 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aleks A
Top achievements
Rank 1
Aleks A asked on 09 Nov 2009, 11:04 AM
Hello i have a rad grid insert edit form popup with a asp.net upload in it. I have made it so that on the button click it makes postback but when the postback returns back the temporary data is lost. How can i from codebehind close all insert/edit forms so i can open the popup from the prerender event? with this code:

            RadGridCardDetails.MasterTableView.FindItemByKeyValue("CardDetailsID", new Guid(HiddenShowCardDetailID.Value)).Edit = true;
            RadGridCardDetails.Rebind();

14 Answers, 1 is accepted

Sort by
0
Aleks A
Top achievements
Rank 1
answered on 09 Nov 2009, 11:29 AM
I have tried different methods to fire the edit method after insert. But the windows that first shows is a standard insert popup in initial settings, how can i close these windows in a specific moment. Like on postback, before we added ajax the e.canceled =true command worked. BUt now it doesn't ?
0
Shinu
Top achievements
Rank 2
answered on 09 Nov 2009, 11:58 AM
Hi Aleks,

Give a try with following approach and see whether it helps.

CS:
 
    bool check = false
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        if (!check) 
        { 
            RadGrid1.MasterTableView.Items[0].Edit = true// Put the corresponding row in editmode (initially) 
            RadGrid1.MasterTableView.Rebind(); 
        } 
    } 
    protected void Button2_Click(object sender, EventArgs e) 
    { 
        check = true;  
        RadGrid1.MasterTableView.IsItemInserted = false
        RadGrid1.MasterTableView.ClearEditItems(); 
    } 

-Shinu.
0
Aleks A
Top achievements
Rank 1
answered on 19 Nov 2009, 08:36 AM
Thanks for the info but I solved it a different way, the problem was i had 2 rebinds on the radgrid after removing them the post back occurred and I continued on the insert form where I handled other code. Now I have a different problem after the popup is done and button pressed for insert or edit command everything works fine but the popup doesn't close. How can i close the edit form popup from codebehind or javascript ?
My grid:
   <telerik:RadGrid runat="server" ID="RadGridCardDetails" EnableViewState="true" AutoGenerateColumns="False" 
                            ShowStatusBar="true" Skin="Vista" AllowAutomaticDeletes="True" AllowAutomaticInserts="True" 
                            AllowAutomaticUpdates="True" OnNeedDataSource="RadGridCardDetails_NeedDataSource" 
                            AllowPaging="True" AllowSorting="True" HorizontalAlign="NotSet" GridLines="None" 
                            OnItemCommand="RadGridCardDetails_ItemCommand" OnUpdateCommand="RadGridCardDetails_UpdateCommand" 
                            OnInsertCommand="RadGridCardDetails_InsertCommand" OnDeleteCommand="RadGridCardDetails_DeleteCommand" 
                            OnItemDataBound="RadGridCardDetails_ItemDataBound" OnItemCreated="RadGridCardDetails_ItemCreated" 
                            OnPreRender="RadGridCardDetails_PreRender"
                            <PagerStyle Mode="NextPrevAndNumeric" /> 

   <asp:Button ID="btnUpdate" OnClientClick="setValueIsUpdate()" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' 
                                            runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>' 
                                            CausesValidation="True" ValidationGroup="ValidationTextField"></asp:Button> 
                                        <asp:Button ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel"></asp:Button> 
                                    </FormTemplate> 
                                    <PopUpSettings ScrollBars="None" /> 
                                </EditFormSettings> 
                            </MasterTableView> 
                        </telerik:RadGrid> 

editFormItem.Display = false; and  e.Canceled = true; don't work. in my    protected void RadGridCardDetails_UpdateCommand(object source, GridCommandEventArgs e) event.
0
Princy
Top achievements
Rank 2
answered on 19 Nov 2009, 01:34 PM
Hello

If you are performing manual insert and update operations, then you should not be setting the AllowAutomaticInserts/AllowAutomaticUpdates to true which is why the forms do not close on hitting the update or insert buttons. Also the automatic operations work only when binding the grid to a declarative data source using the DataSourceID property of the grid. Hence, try setting the AllowAutomaticInserts/AllowAutomaticUpdates properties of the grid to false and see if it helps.

Thanks
Princy.
0
Aleks A
Top achievements
Rank 1
answered on 02 Dec 2009, 09:29 AM
That is true, I am doing manual updates and inserts and when removing that property the pop-up closes, but I have an asp.net upload box in the insert form pop-up and the upload always has to do a postback on the server so sometimes i need the popup to reopen. There has to be a programmable way to close the popup from codebehind. This seems to work on update but not on insert:
RadGridCardDetails.EditIndexes.Clear();
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Dec 2009, 09:42 AM
Hello Aleks,

Try the following code and see if it helps to close the pop up on insert:
c#:
RadGridCardDetails.MasterTableView.IsItemInserted = false
RadGridCardDetails.MasterTableView.Rebind(); 

Thanks
Princy.
0
Aleks A
Top achievements
Rank 1
answered on 02 Dec 2009, 10:07 AM
Thanx a lot Princy that worked perfectly, i had to do it in my prerender method because in my insert event gave me eror on rebinding.
Here is my prerender for anyone else :

protected void RadGridCardDetails_PreRender(object sender, EventArgs e) 
        { 
            if (Session["ItemInserted"] != null && Session["ItemInserted"] == "True") 
            { 
                RadGridCardDetails.EditIndexes.Clear(); 
                RadGridCardDetails.MasterTableView.IsItemInserted = false
                RadGridCardDetails.MasterTableView.Rebind();  
            } 
        } 

0
SamErt
Top achievements
Rank 1
answered on 10 Dec 2009, 08:37 AM
Thank you Aleks , thanks a lot for the code snippet.
0
Rohan
Top achievements
Rank 1
answered on 08 Oct 2012, 06:04 AM

Hi all,

How can I pass the properties to edit form user control.
0
Shinu
Top achievements
Rank 2
answered on 08 Oct 2012, 06:26 AM
Hi Rohan,

I am not quite sure about your requirement. I suppose you want to access the usercontrol in radgrid. Here is the sample code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
    {
        GridEditFormItem item = (GridEditFormItem)e.Item;
        UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
        LinkButton link = (LinkButton)userControl.FindControl("LinkButton1");//accessing the controls in usercontrol
        string value = item.GetDataKeyValue("EmployeeID").ToString();//accessing datakeynames
     }
}

Thanks,
Shinu.
0
Rohan
Top achievements
Rank 1
answered on 08 Oct 2012, 07:01 AM
Hi Shinu,
Thanks for replay ...
i am doing the same way but  nothing happens ....

UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);

userControl  getting null value ...

can you please send any example ....
0
Rohan
Top achievements
Rank 1
answered on 09 Oct 2012, 12:38 PM
HI all ,

How to handle the postback within the user control when rad grid is edit for mode..... also i want to use the user control event to Update the record and some operation on user control .... please send any example or site reference ...........
0
Shinu
Top achievements
Rank 2
answered on 10 Oct 2012, 05:04 AM
Hi,

I am not quite sure about your requirement. You can add a usercontrol in EditformSettings as shown below and get a reference to the controls using the following code.
aspx:
<EditFormSettings UserControlName="UserControl.ascx" EditFormType="WebUserControl">
</EditFormSettings>
C#:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e)
{
   GridEditFormItem item = (GridEditFormItem)e.Item;
   UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
   LinkButton link = (LinkButton)userControl.FindControl("LinkButton1");
}

Thanks,
Shinu.
0
Rohan
Top achievements
Rank 1
answered on 10 Oct 2012, 09:31 AM

Hi shinu ,
Thanks for replay

My scenario is – I have one user control with rad grid and and I want to use rad grid edit form functionality to add various user control to rad grid edit form.

I am able to do this ….

But I want to use the event’s in user control or perform some operation in use control according user controls event.  for example I want to check duplicate data entry in rad grid edit user control and show duplicate entry message  to user , I am able to check the duplicate entry of data but ,I am using rad grid ItemDatabound to bind data to user control for this reason  after the postback it show the old data, and my edit for user control is close.  Is there any way to handle the events in user control with rad grid itemdataboud or any other way to handle user control event …………

Tags
Grid
Asked by
Aleks A
Top achievements
Rank 1
Answers by
Aleks A
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Princy
Top achievements
Rank 2
SamErt
Top achievements
Rank 1
Rohan
Top achievements
Rank 1
Share this question
or