Datagrid info to labels in table

S

Sue

Working om web app using VS2003 - I have a datagrid that
displays 5 of 17 fields in a datarow. I have a table
below the datagrid that has 17 labels - one for each
field in the datarow. When the user clicks on a row in
the datagrid, I'm looking for a way to populate the 17
labels in the table with the same datarow information -
preferable without making a trip to the server (VB
please!). Any ideas?

tia,
Sue
 
M

MSFT

Hi Sue,

I think you must add some client script to implement this. For example, you
have such a table to display detail for each row in datagrid:

<TABLE id="Table1" >
<TR>
<TD id="MyItem" > </TD>
<TD id="MyPrice"> </TD>
<TD id="MyTax"> </TD>
</TR>

</TABLE>

To set this table, we can add a client side function to the web form :

<script language="vbscript">

sub setTable(item,price,tax)


Table1.all("MyItem").innerText=item
Table1.all("MyPrice").innerText=price
Table1.all("MyTax").innerText=tax

end sub

</script>

To enable click event in the datagrid:

<asp:DataGrid id="MyDataGrid" runat="server" AutoGenerateColumns="false"
Width="312px" Height="152px">
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
<b>Item </b>
</HeaderTemplate>
<ItemTemplate>
<label onclick="setTable '<%# DataBinder.Eval(Container.DataItem, "Item")
%>','<%# DataBinder.Eval(Container.DataItem, "price") %>','<%#
DataBinder.Eval(Container.DataItem, "Tax") %>' ">
<%# DataBinder.Eval(Container.DataItem, "Item") %>
</label>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

Please notice following line in above code:

<ItemTemplate>
<label onclick="setTable '<%# DataBinder.Eval(Container.DataItem, "Item")
%>','<%# DataBinder.Eval(Container.DataItem, "price") %>','<%#
DataBinder.Eval(Container.DataItem, "Tax") %>' ">
<%# DataBinder.Eval(Container.DataItem, "Item") %>
</label>
</ItemTemplate>

I user a label control to display "Item" from datasource. And , add a call
to SetTable in its click event.

Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Sue

I user a label control to display "Item" from datasource.
And , add a call
to SetTable in its click event.

Hope this help,

Luke
Microsoft Online Support

Luke - perfect! I kept stumbling over how to grab the
fields from the client side. No need to make a trip to the
server. Seems obvious now <sigh>.

Thank!
Sue
 

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

Forum statistics

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

Latest Threads

Top