Datagrid info to labels in table

  • Thread starter Thread starter Sue
  • Start date Start date
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
 
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.)
 
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
 
Back
Top