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

Diffrent ascx in the EditForm for Grid

3 Answers 96 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Henrik Tegman
Top achievements
Rank 1
Henrik Tegman asked on 16 Dec 2010, 01:21 PM
Hello,

I have a RadGrid and I have two diffrent ascx files.
I want to dynamicly load one or the other when the user press the Editbutton is this possible?

I understand that I can set a ascx to load with the

EditFormSettings-UserControlName

But that will set only one ascx for my whole grid. When the user press the Editbutton I have to check that row/item and if a specific Colum has value "1" then I want to show one ascx if it has something else I want to show the other. I tried to catch the ItemDataBound event and change the

RadGrid1.MasterTableView.EditFormSettings.UserControlName

To something else but I guess that is to late and that the usercontrol has already been loaded at this point.
Can I in some way set every row/item to have a diffrent usercontrol open when edit is pressed, or is there another event that I can catch BEFORE the control gets loaded?

Thanks in advance.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Dec 2010, 06:43 AM
Hello Henrik,


Use ItemCommand to set the UserControlName from code behind. Have a look at the code snippet shown below.

Code:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.EditCommandName)
    {
        if ((e.Item as GridDataItem)["ShipVia"].Text == "London")
        {             
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "WebUserControl1.ascx";
        }
        else
        {
            e.Item.OwnerTableView.EditFormSettings.UserControlName = "WebUserControl2.ascx";
        }         
    }
}



-Shinu.
0
Henrik Tegman
Top achievements
Rank 1
answered on 20 Dec 2010, 02:57 PM
Hello,

That helped me a lot!

But I have a new problem, if I open the editform it will stay open even if I do a postback to the page. I have a simple asp:button that when pressed will fill the grid with new data but the editform is still open when I do this, I don't want it to behave this way and I can also get error since the diffrent ascx have diffrent controls in themself and depending on what I load the grid with I need diffrent ascx.

So the ascxes are working fine now, but the editform stays open and I don't want that.

I have tried to turn off the AllowAutomaticXXXX but that doesn't help.

What can I do to fix this?

Thanks in advance
0
Iana Tsolova
Telerik team
answered on 22 Dec 2010, 02:32 PM
Hello Henrik,

Try clearing the grid edit indexes before rebinding the grid:

RadGrid1.EditIndexes.Clear();
RadGrid1.Rebind();


Greetings,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
Tags
Grid
Asked by
Henrik Tegman
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Henrik Tegman
Top achievements
Rank 1
Iana Tsolova
Telerik team
Share this question
or