access gridview cell from client

Discussion in 'ASP .Net' started by Tom, Dec 21, 2006.

  1. Tom

    Tom Guest

    I need to grab the text from a cell in my gridview and pass it in my
    querystring
    I need to do this on the client
     
    Tom, Dec 21, 2006
    #1
    1. Advertisements

  2. Tom

    Mark Rae Guest

    "Tom" <> wrote in message
    news:...

    >I need to grab the text from a cell in my gridview and pass it in my
    >querystring
    > I need to do this on the client


    A GridView is just an HTML table by the time it's been rendered to the
    browser. It has a rows collection, and each row has a cells collection, and
    you can access it client-side with standard JavaScript:
    http://www.google.co.uk/search?sour...2006-28,GGLG:en&q=JavaScript+table+rows+cells
     
    Mark Rae, Dec 21, 2006
    #2
    1. Advertisements

  3. Hello Tom,

    As Milosz and Mark has mentioned, the GridView is rendered as following
    style html table:

    ===============
    <table cellspacing="0" rules="all" border="1" id="GridView1"
    style="width:500px;border-collapse:collapse;">
    <tr>
    <th scope="col">&nbsp;</th><th scope="col">CategoryID</th><th
    scope="col">CategoryName</th><th scope="col">Description</th>
    </tr><tr>
    <td style="width:25%;"><a
    href="javascript:__doPostBack('GridView1','Edit$0')">Edit</a>&nbsp;<a
    href="javascript:__doPostBack('GridView1','Delete$0')">Delete</a></td><td
    style="width:25%;">1</td><td style="width:25%;">Beverages</td><td
    style="width:25%;">Soft drinks, coffees, teas, beers, and ales</td>
    </tr><tr>
    <td style="width:25%;"><a
    href="javascript:__doPostBack('GridView1','Edit$1')">Edit</a>&nbsp;<a
    href="javascript:__doPostBack('GridView1','Delete$1')">Delete</a></td><td
    style="width:25%;">2</td><td style="width:25%;">Condiments</td><td
    style="width:25%;">Sweet and savory sauces, relishes, spreads, and
    seasonings</td>
    </tr><tr>
    <td style="width:25%;"><a
    href="javascript:__doPostBack('GridView1','Edit$2')">Edit</a>&nbsp;<a
    href="javascript:__doPostBack('GridView1','Delete$2')">Delete</a></td><td
    style="width:25%;">3</td><td style="width:25%;">Confections</td><td
    style="width:25%;">Desserts, candies, and sweet breads</td>
    ........................
    ====================

    you can use client-side script to loop through each table row and column.
    e.g.
    =========
    function loop_table()
    {
    var tb = document.getElementById("GridView1");

    var i,j;
    var msg;

    for(i=0; i<tb.rows.length;i++)
    {

    msg += "\r\n" + tb.rows.cells[3].innerText;
    }

    alert(msg);
    }
    ================

    BTW, when would you do the cell value retrieving at client-side? Does it
    occur when a user click a client-side button in each Gridview row? If so,
    you can consider embed javascript in that button's client-side click script
    (with the required data value get from databinding source). e.g.

    ==============
    <asp:TemplateField >
    <ItemTemplate>
    <input type="button" value="button" onclick='alert(<%# "\""
    + Eval("CategoryID") + "\"" %>);' />
    </ItemTemplate></asp:TemplateField>
    ==========

    Hope this helps.

    Sincerely,

    Steven Cheng

    Microsoft MSDN Online Support Lead



    ==================================================

    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
    ications.



    Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 1 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions or complex
    project analysis and dump analysis issues. Issues of this nature are best
    handled working with a dedicated Microsoft Support Engineer by contacting
    Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/subscriptions/support/default.aspx.

    ==================================================



    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Steven Cheng[MSFT], Dec 21, 2006
    #3
  4. Tom

    Mark Rae Guest

    "Tom" <> wrote in message
    news:...

    > what i do is I have a template field that has a link to a details page. I
    > pass the date in the querystring using
    > <#Eval("dateField")#> and it works but the time is in the query string as
    > well as the date, So I want to get the value from the actual cell instead
    > of
    > the data value in the raw form.
    >
    > so instead of seeing:
    > details.aspx?time=1/1/05 12:00 AM
    >
    > I want to see
    > details.aspx?time=1/1/05 in the querystring


    Hmm - I don't think I'd do it they way you're doing it, but nevertheless you
    could try adding the following to your code:

    DataFormatString="{0:d/M/y}" HtmlEncode="false"


    However, there are a couple of issues you should consider:

    1) Your date format is not Y2k-compliant

    2) Your date format is ambiguous because there is no way to tell which is
    the day, month and year.
     
    Mark Rae, Dec 21, 2006
    #4
  5. Tom

    Mark Rae Guest

    "Tom" <> wrote in message
    news:...

    >I got it working I added:
    >
    > Convert.ToDateTime(Eval("time")).ToString("MM/dd/yyyy")


    Cool - it's still ambiguous, though...

    What does e.g. 02/01/2007 mean to you...?
     
    Mark Rae, Dec 21, 2006
    #5
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. news.rcn.com
    Replies:
    1
    Views:
    10,001
    Chris Smith
    Jul 12, 2004
  2. Phillip Roncoroni
    Replies:
    14
    Views:
    1,245
    Toby A Inkster
    Apr 5, 2004
  3. Empire City
    Replies:
    3
    Views:
    511
    Empire City
    Apr 30, 2004
  4. Thomasa Gregg
    Replies:
    1
    Views:
    249
    Eliyahu Goldin
    Jun 9, 2004
  5. thoward
    Replies:
    3
    Views:
    436
    thoward
    Sep 4, 2007
Loading...

Share This Page