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

Dynamic LinkButton persistance

3 Answers 103 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mordaque
Top achievements
Rank 1
Mordaque asked on 29 Jul 2011, 10:05 AM
Hi,

I create dynamic Link Button in my grid depending on DateFields.

I have had a TemplateColumn like this
<telerik:GridTemplateColumn HeaderText="Action" UniqueName="tplColAction">
                    <ItemTemplate>
                        <asp:Panel ID="pnlActionStatut" runat="server" HorizontalAlign="left">
                        </asp:Panel>
                    </ItemTemplate>
</telerik:GridTemplateColumn>

In my code behind i do that

protected void rdGridOpportunite_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item.ItemType != GridItemType.Item && e.Item.ItemType != GridItemType.AlternatingItem) return;
  
        //Get Object Entity
        OpportuniteEntity opp = e.Item.DataItem as OpportuniteEntity;
        if (opp == null) return;
  
        //Get Panel
        Control pnl = e.Item.FindControl("pnlActionStatut");
        if (!(pnl is Panel)) return;
          
        //Get All statut associate of this statut
        List<TypeStatutOpportuniteEntity> statuts = TypeManager.GetStatutAssocieOfStatut(opp.TypeStatut.IDType, Profile.InstanceID).ToList();
        if (statuts.Count == 0) return;
  
        LinkButton lbAction;
          
        //Create LinkButton for each Statut  
        statuts.ForEach(s =>
            {
                lbAction = new LinkButton();
                lbAction.Text = "--> " + s.Libelle;
                lbAction.Click += new EventHandler(lbAction_Click);
                lbAction.CommandArgument = string.Format("{0};{1}", opp.ID, s.IDType);
                lbAction.ID = string.Format("lnkBtn{0}{1}", opp.ID, s.IDType);
                pnl.Controls.Add(lbAction);
                pnl.Controls.Add(new Label() { Text = "<br />" });
            }
        );
    }

My Grid can be expan or collapse and when I Expand or collapse i Lost my control ...
Ditto When I click on LinkButton i lost control too and i can't start GridCommand and lbAction Event click

I have try to make the same code on ItemCreated but the result is the same.

How I can keep my control ??

Thank you.
PS : Sorry for my English

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Jul 2011, 10:14 AM
Hello Mordaque,

Take a look at the following forum thread which discussed similar scenario.
Hyperlinks not retained on postback.

Thanks,
Princy
0
Mordaque
Top achievements
Rank 1
answered on 29 Jul 2011, 11:16 AM
Thank for your answer.

I have always a problem when I expand my row my dynamic links disapear...

I have tried to Rebind the Grid but when i do that i lost the expand command so my Row is never expand ...

I havn't find the solution in your link.

Regards.
0
Pavlina
Telerik team
answered on 03 Aug 2011, 06:31 PM
Hello Mordaque,

I would suggest you to handle the RadGrid_ItemCreated event in order to achieve the required functionality. Please refer to the following forum post which elaborates on similar scenario.

Kind regards,
Pavlina
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
Mordaque
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Mordaque
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or