如何在数据绑定到gridview之后调用javascript函数 [英] how to call javascript function after databind to gridview

查看:50
本文介绍了如何在数据绑定到gridview之后调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试动态生成gridview。

我希望在数据完全绑定到gridview后调用javascript函数。提供解决方案。

解决方案

< blockquote>如果您正在使用JQuery,您可以使用document.getReady方法,该方法将在加载页面的所有内容后调用,当然假设您希望在客户端进行此操作。


如果你在gridView中使用ItemTemplate,那么你需要在属性窗格中启用RowDataBound - >事件。

执行Javascript函数的步骤。

1.Javascript函数在你的aspx页面中



 function fnPopUp(viewDetails){
alert(viewDetails);
}





2.创建templateField:

 < span class =code-keyword><   asp:TemplateField     HeaderText   = 查看信息 >  
< ItemTemplate >
< asp:LinkBut​​ton ID = lnkDisplayPopUp runat = server

文本 =' <% #Eval( ColumnName%> ' onclick = lnkDisplayPopUp_Click > < / asp:LinkBut​​ton >

& nbsp;

< / ItemTemplate >
< / asp:TemplateField >



3.在属性内部的事件中,GridView RowDataBound的窗格指定(GridView_RowDataBound)在GridView代码文件后面创建的函数的名称。

3 。编写此代码。为了注册你的onclick事件。

 protected void GridView_RowDataBound(object sender,GridViewRowE ventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
LinkBut​​ton btnAlert =(LinkBut​​ton)e.Row.FindControl(lnkDisplayPopUp) ;
DataRowView drv =(DataRowView)e.Row.DataItem;
string id = drv [ColumnName]。ToString();
btnAlert.Attributes.Add(onclick,fnPopUp(+ id +); return false;);
}
}


  protected   void  gvListDTL_RowDataBound( object  sender,GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
try
{
HiddenField hdnRM_Qty =(HiddenField)e.Row.FindControl( hdnRM_Qty );
TextBox RM_Qty =(TextBox)e.Row.FindControl( RM_Qty);
RM_Qty.Attributes.Add( onchange FnValidate(' + hdnRM_Qty.ClientID + ',' + RM_Qty.ClientID + '));
}
catch (例外)
{}
}
}


I am trying to generate gridview dynamically.
I want call javascript function after data completely bind to gridview.provide a solution.

解决方案

If you are using JQuery you can use document.getReady method of which will be called after all content of the page are loaded, of course assuming you want this to happen client side.


If you are using ItemTemplate in your gridView then you need to enable "RowDataBound" inside properties pane ->Events.
Steps to execute Javascript function.
1.Javascript function in your aspx page

function fnPopUp(viewDetails) {
        alert(viewDetails);
    }



2. Create templateField :

<asp:TemplateField HeaderText="View Information">
        <ItemTemplate>
        <asp:LinkButton ID="lnkDisplayPopUp" runat="server"

                Text='<%# Eval("ColumnName") %>' onclick="lnkDisplayPopUp_Click" ></asp:LinkButton>

            &nbsp;

        </ItemTemplate>
        </asp:TemplateField>


3. In events inside properties Pane of GridView RowDataBound specify (GridView_RowDataBound) name of the function which is created behind GridView code file .
3. Write This Code.In order to register your onclick event.

protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                LinkButton btnAlert = (LinkButton)e.Row.FindControl("lnkDisplayPopUp");
                DataRowView drv = (DataRowView)e.Row.DataItem;
                string id = drv["ColumnName"].ToString();
                btnAlert.Attributes.Add("onclick", "fnPopUp("+id+");return false;");
            }
        }


protected void gvListDTL_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
               try
               {
                   HiddenField hdnRM_Qty = (HiddenField)e.Row.FindControl("hdnRM_Qty");
                   TextBox RM_Qty = (TextBox)e.Row.FindControl("RM_Qty");
                   RM_Qty.Attributes.Add("onchange", "FnValidate('"+hdnRM_Qty.ClientID+"','"+RM_Qty.ClientID+"')");
               }
               catch (Exception)
               { }
           }
       }


这篇关于如何在数据绑定到gridview之后调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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