Click here to Skip to main content
15,893,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,
I'm stuck in this little trouble. Please help me. I have a GridView gvList. In this GridView, I want to use Ajax popupcontrol
which will pop up a treeview.
XML
<asp:GridView ID="gvList" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvRowDataBound" AllowPaging="false" AlternatingRowStyle-CssClass="alt2" class="table_title" CssClass="table_title" RowStyle-CssClass="alt" Width="100%">
   
<Columns>
<asp:TemplateField HeaderText="Action By">
  <ItemTemplate>
   <asp:TextBox ID="txtActionBy" runat="server"></asp:TextBox>
    <ajaxToolkit:PopupControlExtender ID="ajaxActionBy" BehaviorID="actionByBehavior"  runat="server" TargetControlID="txtActionBy" PopupControlID="pnlTreeView" Position="Bottom">
 </ajaxToolkit:PopupControlExtender>

  <asp:Panel ID="pnlTreeView" BackColor="White" runat="server" Width="200px" ScrollBars="Auto" style="max-height:200px;display:none;">

  <asp:TreeView ID="trview" BackColor="White" runat="server" ShowCheckBoxes="All" ShowExpandCollapse="true"></asp:TreeView><br />

<asp:CheckBox ID="chkOther" runat="server" Text="Other" Enabled="false" />
   
<asp:TextBox ID="txtOther" runat="server" Enabled="false" Width="200px"></asp:TextBox>
   </asp:Panel>
                                    
   </ItemTemplate>
      </asp:TemplateField>
</Columns>
</asp:GridView>


At code behind, I have this:

C#
protected void gvRowDataBound(object sender, GridViewRowEventArgs e)
 {

if (e.Row.RowType == DataControlRowType.DataRow)
{
TextBox txtActionBy = (TextBox)findControl(e.Row, "txtActionBy");

txtActionBy.Attributes.Add("onfocus", "ShowPopup('" + ajaxActionBy + "')");
TreeViewDataBind();
}
}

My JavaScript is as follows:
C#
function ShowActionBy(popupId) {

    var popup = $find('actionByBehavior');
        if(popup!=null){
            popup.showPopup();
        }
        }

But my popup works only in first row of the gridview. what is the fact ? Please anyone help.
Posted

I have been used the same concept in my project. it looks similar to your requirement, have a look, it might helps.
Design:
ASP.NET
<columns>
                                <asp:boundfield datafield="TraineeId" headertext="TraineeId" xmlns:asp="#unknown" />
                                <asp:boundfield datafield="Subject" headertext="Subject" xmlns:asp="#unknown" />
                                <asp:templatefield itemstyle-width="40" itemstyle-horizontalalign="Right" xmlns:asp="#unknown">
                                    <itemtemplate>
                                        <asp:image id="Image1" runat="server" imageurl="~/Images/magnify.gif" />
                                        <ajax:popupcontrolextender id="PopupControlExtender1" runat="server" popupcontrolid="Panel1" xmlns:ajax="#unknown">
                                            TargetControlID="Image1" DynamicContextKey='<%# Eval("NotificationId") %>' DynamicControlID="Panel1"
                                            DynamicServiceMethod="GetDynamicContent" Position="Bottom">
                                        </ajax:popupcontrolextender>
                                    </itemtemplate>
                                </asp:templatefield>
                            </columns>

Code behind:
C#
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
        public static string GetDynamicContent(string contextKey)
        {

            //string constr = "Server=TestServer;Database=SampleDatabase;uid=test;pwd=test;";
            //string query = "SELECT UnitPrice, UnitsInStock, Description FROM Products WHERE ProductID = " + contextKey; 


            SqlConnection SqlCon = new SqlConnection("Data Source=V_rrd2005;Initial Catalog=TrainingDemo;User ID=sa;Password=sa4vij;Asynchronous Processing=true");
            SqlCommand SqlCom = new SqlCommand();
            DataTable dataTable = null;

            dataTable = new DataTable();
            SqlCom.Connection = SqlCon;
            SqlCom.CommandText = "SELECT * FROM [Notifications] where NotificationId=" + contextKey + " ";
            SqlDataAdapter ad = new SqlDataAdapter(SqlCom);
            ad.Fill(dataTable);


            StringBuilder b = new StringBuilder();

            b.Append("<table style="background-color:#f3f3f3; border: #336699 3px solid; ");<br mode="hold" />            b.Append("width:350px; font-size:10pt; font-family:Verdana;" cellspacing="0" cellpadding="3">");

            b.Append("<tr><td colspan="4" style="background-color:#336699; color:white;">");
            b.Append("Product Details"); b.Append("</td></tr>");
            b.Append("<tr><td style="width:80px;">BatchId</td>");
            b.Append("<td style="width:80px;">TraineeId</td>");
            b.Append("<td style="width:80px;">Description</td>");
            b.Append("<td>Priority</td></tr>");

            b.Append("<tr>");
            b.Append("<td>" + dataTable.Rows[0]["BatchId"].ToString() + "</td>");
            b.Append("<td>" + dataTable.Rows[0]["TraineeId"].ToString() + "</td>");
            b.Append("<td>" + dataTable.Rows[0]["Description"].ToString() + "</td>");
            b.Append("<td>" + dataTable.Rows[0]["Priority"].ToString() + "</td>");

            b.Append("</tr>");

            b.Append("</table>");

            return b.ToString();

        }


css:

CSS
<style type="text/css">
        .fixedHeader
        {
            /*font-weight: bold;
            background-color: #006699;
            color: #ffffff;*/
            
            height: 25px;
            position: absolute;
            top: expression(Sys.UI.DomElement.getBounds(document.getElementById("panelContainer")).y-25);
        }
    </style>
 
Share this answer
 
Thanks for your time Sanjeev. I've solved this myself like follows:
I've added onrowcreated in gvList
C#
protected void gvRowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                AjaxControlToolkit.PopupControlExtender pce = (AjaxControlToolkit.PopupControlExtender)e.Row.FindControl("ajaxActionBy");

                // Set the BehaviorID
                string behaviorID = string.Concat("pce", e.Row.RowIndex);
                pce.BehaviorID = behaviorID;

                // Programmatically reference the Image control
                TextBox txtActionBy = (TextBox)e.Row.Cells[1].FindControl("txtActionBy");

                // Add the clie nt-side attributes (onmouseover & onmouseout)
                string onfocus = string.Format("$find('{0}').showPopup();", behaviorID);
                
                txtActionBy.Attributes.Add("onfocus", onfocus);
                
            }
        }
 
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