I have page Webform1.aspx and one GrvData.ascx user control. i am dynamically displaying usercontrol in webfom1.aspx page... i want to access grvitem in webform1.aspx.cs which is in GrvData.ascx. full design and code is bellow..

我有页面Webform1.aspx和一个GrvData.ascx用户控件。我在webfom1.aspx页面中动态显示usercontrol ...我想访问grvData.ascx中的webform1.aspx.cs中的grvitem。完整的设计和代码如下:

webform1.aspx

<form runat="server">
<input type="button" value="Load" runat="server" />
<input type="button" value="Submit" runat="server" />
<div id="result"></div>
</form>
<script>
$(document).ready(function () {  
// on load button click jquery      
        $.ajax({
            type: "POST",
            url: "Webform1.aspx/Result",
            data: "{ ClientIDD : '" + clientidd + "'}",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {               
                $('#result').html(response.d);
            },
            error: function (msg) {               
                alert(msg);               
            }       
    });
}); 
</script>

code behind

Webform1.aspx.cs

  [WebMethod]
    public static string Result(string ClientIDD)
    {
        return Results(ClientIDD);
    }

    public static string Results(string ClientIDD)
    {
        try
        {
            Page page = new Page();
            System.Web.UI.UserControl userControl = (System.Web.UI.UserControl)page.LoadControl("GrvData.ascx");

            Type t = userControl.GetType();
            MethodInfo addtext = t.GetMethod("BindMyGrid");
            addtext.Invoke(userControl, new object[] { ClientIDD });
           // ControlHub.Controls.Add(userControl);

            userControl.EnableViewState = true;
            HtmlForm form = new HtmlForm();
            form.Controls.Add(userControl);
            page.Controls.Add(form);

            StringWriter textWriter = new StringWriter();                
            HttpContext.Current.Server.Execute(page, textWriter,false);              
            return textWriter.ToString();

        }
        catch (Exception ex)
        {
            return ex.ToString();
        }
    }

GrvData.ascx

<asp:gridview id="grvitem" runat="server" 
        width="100%" autogeneratecolumns="False"
        datakeynames="ID" EmptyDataText="No records found" >          
            <Columns>               
                <asp:TemplateField >
                <ItemTemplate >
                    <input type="checkbox" id="chk" value="getIndex" onclick="chng(<%# Eval("Amount") %>,this);" />                
                </ItemTemplate>
            </asp:TemplateField>               
                <asp:BoundField DataField="ServiceName" HeaderText="Description" />                               
                <asp:BoundField HeaderText="Rate" DataField="Rate" />
                <asp:BoundField HeaderText="QTY" DataField="QTY" />               
                 <asp:TemplateField HeaderText="Price">
    <ItemTemplate>
        <asp:Label ID="lblListPrice" runat="server" Text='<%#Eval("Amount")%>'/>
    </ItemTemplate>
    </asp:TemplateField> 
            </Columns>             
        </asp:gridview>

Code Behind

public void BindMyGrid(string clientid)
        {      
            // bind the data to the grid
            grvitem.DataSource = data;
            grvitem.DataBind();
        }

Please tell me how to access grvitem in webform1.aspx.cs...

请告诉我如何在webform1.aspx.cs中访问grvitem ...

1 个解决方案

#1


0

If you return HTML content from server please remove the following from your jQuery ajax call

如果从服务器返回HTML内容,请从jQuery ajax调用中删除以下内容

contentType: "application/json; charset=utf-8",
dataType: "json",

Since it requests JSON as return type

因为它请求JSON作为返回类型

更多相关文章

  1. 加载函数加载页面但不能对数据执行任何操作
  2. 在Woocommerce结帐页面使用AJAX和Fee API进行动态折扣
  3. 从一个页面上的AJAX帖子获得NTLM挑战
  4. Web App可以在不刷新页面的情况下最好地添加,删除和编辑行
  5. jquery蔚蓝网总结三个页面
  6. Fullcalendar:为什么日历在页面上出现两次?
  7. jQuery使用微调器加载整个HTML页面
  8. 基于jQuery实现页面搜索功能----项目实战
  9. js jquery 关闭弹出页面 并刷新父页面(window.opener)

随机推荐

  1. android 的中文意思
  2. Android 仿QQ多级列表框实现
  3. 针对Android 平板的海豚浏览器正式版推出
  4. Android Wear Preview - 设计规范(Design
  5. android root后数据安全
  6. android屏保源码
  7. Android--ListView 分割线
  8. android API版本对应的系统版本及Android
  9. default locale 设置地区
  10. android EditText 不自动获取焦点并弹出