files as attachments.

On 7/8/06, Jon Ceanfaglione <[EMAIL PROTECTED]> wrote:
Here's the Ajax enabled grid.


ASPX code

 <form id="form1" runat="server">
    <div>
        <script type="text/_javascript_">
            function FilterList()
            {
                var filter = document.getElementById("txtFilter");
               
                SimpleList.AjaxBind(filter.value, fl_callback);
            }
           
            function fl_callback(response)
            {
                if(response.error != null)
                { 
                    alert(response.error.Message);
                }
                else   
                {
                     //alert(response.value);
                     document.getElementById('divGrid').innerHTML = response.value;
                }
              
            }
        </script>
        filter grid: <input name="txtFilter" id="txtFilter" value="" /> <input type="button" value="filter results" />

        <div id="divGrid" runat="server">
       
        </div>
    </div>
    </form>


ASPX.CS code

 protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(SimpleList));

        string filter = null;

        if (!Page.IsPostBack)
        {
            System.Web.UI.WebControls.DataGrid grid = new DataGrid();
            grid.DataSource = GetNames(filter);
            grid.DataBind();

            this.divGrid.Controls.Add(grid);
        }
    }

    [AjaxPro.AjaxMethod()]
    public string AjaxBind(string filter)

    {
        System.Web.UI.WebControls.DataGrid grid = new DataGrid();
        grid.DataSource = GetNames(filter);
        grid.DataBind();

        return this.RenderControlToString(grid);
    }

    private string RenderControlToString(Control c)
    {
        StringBuilder sb = new StringBuilder();
        System.IO.StringWriter sw = new System.IO.StringWriter(sb);

        HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
        c.RenderControl(htmlWriter);

        return sb.ToString();
    }

    private List<string> GetNames(string filter)
    {
        List<string> baseList = new List<string>();
        baseList.Add("Tom");
        baseList.Add("Tomas");
        baseList.Add("Thomas");
        baseList.Add("Tomassen");
        baseList.Add("Thomasen");

        if(filter != null)
        {
            List<string> filteredList = new List<string>();

            foreach (string s in baseList)
            {
                if (s.ToLower ().IndexOf(filter.ToLower()) > -1)
                {
                    filteredList.Add(s);
                }
            }

            baseList = filteredList;
        }

        return baseList;
    }

On 7/8/06, Jon Ceanfaglione < [EMAIL PROTECTED]> wrote:
Sure, consider the following *traditional* aspx sample which has a textbox that takes a string to filter a list and then binds to a grid.

ASPX code

<form id="form1" runat="server">
    <div>
        filter grid: <input name="txtFilter" id="txtFilter" value="" /> <input type="submit" value="filter results" />
        <div id="divGrid" runat="server">
       
        </div>
    </div>
    </form>

ASPX.CS code

protected void Page_Load(object sender, EventArgs e)
    {
        string filter = null;

        if (Page.IsPostBack )
        {
            filter = Request.Form["txtFilter"];
        }

        System.Web.UI.WebControls.DataGrid grid = new DataGrid();
        grid.DataSource = GetNames(filter);
        grid.DataBind ();

        this.divGrid.Controls.Add(grid);
    }

    private List<string> GetNames(string filter)
    {
        List<string> baseList = new List<string>();
        baseList.Add ("Tom");
        baseList.Add("Tomas");
        baseList.Add("Thomas");
        baseList.Add("Tomassen");
        baseList.Add("Thomasen");

        if(filter != null)
        {
            List<string> filteredList = new List<string>();

            foreach (string s in baseList)
            {
                if (s.ToLower().IndexOf(filter.ToLower()) > -1)
                {
                    filteredList.Add(s);
                }
            }

            baseList = filteredList;
        }

        return baseList;
    }

To AJAX enable this you could add the following helper method to generate the HTML and then pass the HTML back to the client using the AJAX library.  Once you have it back to the client, something like document.getElementById('divGrid').innerHTML = result;

        public string RenderControlToString(Control c)
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
            c.RenderControl(htmlWriter);

            return sb.ToString();
        }

It will take me some time, but I can post a working example later,


On 7/8/06, CalleManthey < [EMAIL PROTECTED]> wrote:

Jon,

can you provide a little example or pseudocode for that?
I don't get the trick.

Thanks

Calle

Jon Ceanfaglione schrieb:

> Chandon
>
> Michael is correct - there is no way to bind a datagrid using AjaxPro.Net.
> However, there are ways to use the library to enable the DataGrid using the
> AjaxPro library.  For example, bind the grid as you normally would on page
> load, but use AjaxPro as a callback mechanism to render the html that the
> datagrid would. If you use the datagrid control programatically, i.e. in the
> code behind, and never add it to the page controls, you can get the datagrid
> to do all the things standard of the control, but render the control as a
> string of html and use _javascript_ on the client side to add to a "div" tag.
> Then you get Ajax-like behavior of the control.
>
> On 7/7/06, Michael Schwarz < [EMAIL PROTECTED]> wrote:
> >
> >
> > Hi,
> >
> > if you do a search here in the Google group you will find that this is
> > not possible. You have to return a DataTable or DataSet and loop over
> > all rows building a table with _javascript_.
> >
> > http://www.ajaxpro.info/datagrid.aspx
> >
> > Regards,
> > Michael
> >
> > On 7/7/06, chandan <[EMAIL PROTECTED]> wrote:
> > >
> > >
> > > Hi,
> > >
> > >  I am new in AJAX tech. can any body help me, can any body tell me that
> > > how can i bind my data grid using AJAX.
> > >
> > >
> > > Thanks & Regards
> > > Chandan Tandon
> > >
> > >
> > > >
> > >
> >
> >
> > --
> > Best regards | Schöne Grüße
> > Michael
> >
> > Microsoft MVP - Most Valuable Professional
> > Microsoft MCAD - Certified Application Developer
> >
> > http://weblogs.asp.net/mschwarz/
> > http://www.schwarz-interactive.de/
> > mailto: [EMAIL PROTECTED]
> >
> > >
> >
>
> ------=_Part_12223_3159482.1152278729617
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: quoted-printable
> X-Google-AttachSize: 2248
>
> Chandon<br><br>Michael is correct - there is no way to bind a datagrid using AjaxPro.Net.&nbsp; However, there are ways to use the library to enable the DataGrid using the AjaxPro library.&nbsp; For example, bind the grid as you normally would on page load, but use AjaxPro as a callback mechanism to render the html that the datagrid would. If you use the datagrid control programatically,
> i.e. in the code behind, and never add it to the page controls, you can get the datagrid to do all the things standard of the control, but render the control as a string of html and use _javascript_ on the client side to add to a &quot;div&quot; tag.&nbsp; Then you get Ajax-like behavior of the control.
> <br><br><div><span class="gmail_quote">On 7/7/06, <b class="gmail_sendername">Michael Schwarz</b> &lt;<a href="" href="mailto:[EMAIL PROTECTED]" target="_blank" > [EMAIL PROTECTED]">[EMAIL PROTECTED]</a>&gt; wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
> <br>Hi,<br><br>if you do a search here in the Google group you will find that this is<br>not possible. You have to return a DataTable or DataSet and loop over<br>all rows building a table with _javascript_.<br><br><a href="" http://www.ajaxpro.info/datagrid.aspx">
> http://www.ajaxpro.info/datagrid.aspx</a><br><br>Regards,<br>Michael<br><br>On 7/7/06, chandan &lt;<a href="" [EMAIL PROTECTED]"> [EMAIL PROTECTED]</a>&gt; wrote:<br>&gt;<br>&gt;<br>&gt; Hi,<br>&gt;<br>&gt;&nbsp;&nbsp;I am new in AJAX tech. can any body help me, can any body tell me that
> <br>&gt; how can i bind my data grid using AJAX.<br>&gt;<br>&gt;<br>&gt; Thanks &amp; Regards<br>&gt; Chandan Tandon<br>&gt;<br>&gt;<br>&gt; &gt;<br>&gt;<br><br><br>--<br>Best regards | Schöne Grüße<br>Michael<br><br>Microsoft MVP - Most Valuable Professional
> <br>Microsoft MCAD - Certified Application Developer<br><br><a href="" href="http://weblogs.asp.net/mschwarz/" target="_blank" >http://weblogs.asp.net/mschwarz/ "> http://weblogs.asp.net/mschwarz/</a><br><a href="" href="http://www.schwarz-interactive.de/" target="_blank" >http://www.schwarz-interactive.de/ ">http://www.schwarz-interactive.de/
> </a><br>mailto:<a href="" href="mailto:[EMAIL PROTECTED]" target="_blank" >[EMAIL PROTECTED]"> [EMAIL PROTECTED] </a><br><br>
> ------=_Part_12223_3159482.1152278729617--





--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ajax.NET Professional" group.

To post to this group, send email to ajaxpro@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]

For more options, visit this group at http://groups.google.com/group/ajaxpro

The latest downloads of Ajax.NET Professional can be found at http://www.ajaxpro.info
-~----------~----~----~----~------~----~------~--~---

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class SimpleList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AjaxPro.Utility.RegisterTypeForAjax(typeof(SimpleList));
        string filter = null;

        if (!Page.IsPostBack)
        {
            System.Web.UI.WebControls.DataGrid grid = new DataGrid();
            grid.DataSource = GetNames(filter);
            grid.DataBind();

            this.divGrid.Controls.Add(grid);
        }
    }

    [AjaxPro.AjaxMethod()]
    public string AjaxBind(string filter)
    {
        System.Web.UI.WebControls.DataGrid grid = new DataGrid();
        grid.DataSource = GetNames(filter);
        grid.DataBind();

        return this.RenderControlToString(grid);
    }

    private string RenderControlToString(Control c)
    {
        StringBuilder sb = new StringBuilder();
        System.IO.StringWriter sw = new System.IO.StringWriter(sb);
        HtmlTextWriter htmlWriter = new HtmlTextWriter(sw);
        c.RenderControl(htmlWriter);

        return sb.ToString();
    }

    private List<string> GetNames(string filter)
    {
        List<string> baseList = new List<string>();
        baseList.Add("Tom");
        baseList.Add("Tomas");
        baseList.Add("Thomas");
        baseList.Add("Tomassen");
        baseList.Add("Thomasen");

        if(filter != null)
        {
            List<string> filteredList = new List<string>();

            foreach (string s in baseList)
            {
                if (s.ToLower().IndexOf(filter.ToLower()) > -1)
                {
                    filteredList.Add(s);
                }
            }

            baseList = filteredList;
        }

        return baseList;
    }
}

Attachment: SimpleList.aspx
Description: application/xml

Reply via email to