Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is aspx code in which I put a grid view in ajax panel.

XML
<body>
        <form id="form1" runat="server">
        <div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">
            </asp:ScriptManager>

            <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
            <asp:GridView ID="GridView1" runat="server" DataKeyNames="head_code" >
            </asp:GridView>
            
            </ContentTemplate>
            </asp:UpdatePanel>

        </div>
        </form>
    </body>


Following is code behind:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace gridview_button
{

    public partial class WebForm2 : System.Web.UI.Page, ITemplate
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            hitechLatestEntities database = new hitechLatestEntities();
            GridView1.DataSource = database.HEADs;

            TemplateField tfObject = new TemplateField();
            tfObject.HeaderText = "Sub-Head";

            tfObject.ItemTemplate = new WebForm2(ListItemType.Item);

            GridView1.Columns.Add(tfObject);
            GridView1.DataBind();

        }

       /////////////////////////////// For template field //////////////////////////////////

        public WebForm2()
        {
        }

        public WebForm2(ListItemType Item)
        {
            myListItemType = Item;
        }

        private ListItemType myListItemType;

        public void InstantiateIn(Control container)
        {

            if (myListItemType == ListItemType.Item)
            {
                Button btn = new Button();
                container.Controls.Add(btn);
            }
        }

      ////////////////////////////////////////////////////////////////////////////////////
    }

}

I have created template field dynamically and Above code is working fine but only problem is that every time when i click on button in template field, a new blank template field column appears with same header text. Even ajax is not working for me.
or
can anyone tell me how to add btn to UpdatePanel1 dynamically??
Posted
Updated 30-Jan-14 2:14am
v6
Comments
Tom Marvolo Riddle 30-Jan-14 7:48am    
I'm not sure try with toolscriptmanager

1 solution

C#
<asp:updatepanel id="UpdatePanel1" updatemode="Conditional" runat="server" xmlns:asp="#unknown">
  </asp:updatepanel>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900