Blank value returned on ItemDataBound event using e.Item.Cells

Discussion in 'ASP .Net Datagrid Control' started by JC, Jul 15, 2004.

  1. JC

    JC Guest

    Hi,

    I have a datagrid and want to be able to assess the value of one cell
    on each line in order to hide or display the hyperlink in the next
    cell. I therefore used the ItemDataBound, and intially wrote the cell
    values to screen (to test it) - however, for some reason only only the
    first column rows are visble?

    The first column is just text, the second is a TemplateColumn - could
    this be a problem? If so, any ideas how to get around it?

    Any help would be appreciated:

    *****************************CODE BEHIND*****************************
    private void dgCreationTermination_ItemDataBound(object sender,
    System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if((e.Item.ItemType == ListItemType.AlternatingItem) ||
    (e.Item.ItemType == ListItemType.Item) )
    {

    Response.Write(e.Item.Cells[0].Text + "<br>");
    Response.Write(e.Item.Cells[1].Text + "<br>");
    Response.Write(e.Item.Cells[2].Text + "<br>");
    }
    }
    ********************************************************************
    ****************************PAGE CODE*******************************
    <asp:DataGrid id="dgCreationTermination" runat="server"
    CssClass="phonebookContent" Width="500px" AutoGenerateColumns="False">
    <AlternatingItemStyle
    CssClass="phonebookContentAlternate"></AlternatingItemStyle>
    <HeaderStyle CssClass="tableHeader"></HeaderStyle>
    <Columns>
    <asp:BoundColumn DataField="name" HeaderText="Staff
    Name"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Status">
    <ItemTemplate>
    <%#(formatStatusStaff((int)DataBinder.Eval(Container.DataItem,"status")))%>
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:HyperLinkColumn Text="view" DataNavigateUrlField="id"
    DataNavigateUrlFormatString="viewStaffMember.aspx?id={0}"></asp:HyperLinkColumn>
    </Columns>
    </asp:DataGrid>
    **************************************************************************
    JC, Jul 15, 2004
    #1
    1. Advertising

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. MattB
    Replies:
    4
    Views:
    21,270
  2. gane
    Replies:
    2
    Views:
    3,123
  3. GaryDean
    Replies:
    1
    Views:
    8,688
    Walter Wang [MSFT]
    Aug 18, 2006
  4. NH
    Replies:
    2
    Views:
    527
    Andrew L. Van Slaars
    Dec 17, 2004
  5. VBTECH

    e.Item.Cells.Count in UpdateCommand event of Datagrid

    VBTECH, Apr 21, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    253
    Brock Allen
    Apr 21, 2005
Loading...

Share This Page