access gridview cell from client

T

Tom

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
 
S

Steven Cheng[MSFT]

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.
 
M

Mark Rae

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.
 
M

Mark Rae

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...?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top