Getting to the data in a cell

Discussion in 'ASP .Net Datagrid Control' started by Tim, Apr 29, 2004.

  1. Tim

    Tim Guest

    Hi, anyone know how I can get to the cell: "<td><%#
    DataBinder.Eval(Container.DataItem, "USL")%></td>" in the below code to
    change it?
    Please let me know if I should design it different.

    This is how deep I have to go in the DataGrid (highlighted in blue)...


    Quote:

    <Columns>
    <asp:TemplateColumn>
    <ItemTemplate>
    <table>
    <tr>
    <td><%# DataBinder.Eval(Container.DataItem, "NAME")%></td>
    </tr>
    <tr>
    <td><%# DataBinder.Eval(Container.DataItem, "CITY")%>
    <%# DataBinder.Eval(Container.DataItem, "STATE")%>
    </td>
    </tr>

    <tr>
    <td><%# DataBinder.Eval(Container.DataItem, "USL")%></td>
    </tr>

    </table>
    </ItemTemplate>
    </asp:TemplateColumn>
    </Columns>

    I try this....

    Quote:


    public void ItemDataBoundEventHandler(object sender, DataGridItemEventArgs
    e){
    if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem){
    string aoru="";
    aoru=Convert.ToString(DataBinder.Eval(e.Item.DataItem, "USL"));
    if(aoru==""){
    e.Item.Cells[0].Text="ASL";
    }else{
    e.Item.Cells[0].Text="USL";
    }}}

    But it looks like it is only picking up the "<asp:TemplateColumn>" no
    deeper.

    Any idea how I can get to the cell:
    <td><%# DataBinder.Eval(Container.DataItem, "USL")%></td>
    and change the value in it?

    I need to have multi values in the cell but need to be able to reach one of
    the values with code.

    Thanks for your help!
     
    Tim, Apr 29, 2004
    #1
    1. Advertisements

  2. Tim, put the <%# ... %> stuff in a Label control:

    <asp:Label id="someID" runat="server" Text='<%# ... %>' />

    Then use FindControl("someID") in your code-behind class to reference
    the Label Web control. For more info on using FindControl() to
    reference a control in a Template, see:
    http://datawebcontrols.com/faqs/ProgrammaticAccess/AccessingTemplateColumnContents.shtml

    hth

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], May 1, 2004
    #2
    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. OrlandoRocks
    Replies:
    1
    Views:
    2,923
    Teemu Keiski
    Jan 4, 2004
  2. news.rcn.com
    Replies:
    1
    Views:
    10,242
    Chris Smith
    Jul 12, 2004
  3. Phillip Roncoroni
    Replies:
    14
    Views:
    1,376
    Toby A Inkster
    Apr 5, 2004
  4. Empire City
    Replies:
    3
    Views:
    632
    Empire City
    Apr 30, 2004
  5. Thomasa Gregg
    Replies:
    1
    Views:
    312
    Eliyahu Goldin
    Jun 9, 2004
  6. RJ
    Replies:
    1
    Views:
    412
    Eliyahu Goldin
    Feb 17, 2005
  7. Prasad Peesapati

    Making a cell editable on clicking the cell

    Prasad Peesapati, Feb 3, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    207
    Prasad Peesapati
    Feb 3, 2005
  8. Replies:
    2
    Views:
    462
    Thomas 'PointedEars' Lahn
    Aug 5, 2008
Loading...