gridview中的Ajax popupcontrol [英] Ajax popupcontrol within a gridview

查看:83
本文介绍了gridview中的Ajax popupcontrol的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我陷入了这个小麻烦。请帮我。我有一个GridView gvList。在这个GridView中,我想使用Ajax popupcontrol

,它会弹出一个树视图。

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.

<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:

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();

}

}



我的JavaScript如下:


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:

function ShowActionBy(popupId) {

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



但我的弹出窗口仅适用于gridview的第一行。事实是什么?请任何人帮忙。


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

推荐答案

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



但我的弹出窗口仅适用于gridview的第一行。事实是什么?请任何人帮忙。


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


我在项目中使用了相同的概念。它看起来类似于你的要求,看看,它可能会有所帮助。

设计:

I have been used the same concept in my project. it looks similar to your requirement, have a look, it might helps.
Design:
<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:

[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>


感谢您的时间Sanjeev。我已经解决了这个问题,如下所示:

我在gvList中添加了onrowcreated

Thanks for your time Sanjeev. I''ve solved this myself like follows:
I''ve added onrowcreated in gvList
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("


这篇关于gridview中的Ajax popupcontrol的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆