datagrid: can't get read text from a cell programmatically

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default datagrid: can't get read text from a cell programmatically

    In the event handler for ItemCommand, I am trying to read text of cells in
    the row programmatically, but can't get it working.

    //this is what I have in InitializeComponent
    this.dgList.ItemCommand += new
    System.Web.UI.WebControls.DataGridCommandEventHand ler(this.dgList_Command);

    //this is the event handler.
    private void dgList_Command(object sender, DataGridCommandEventArgs e)
    {
    if(e.CommandName == "View")
    {
    Response.Write(e.Item.Cells.Count);
    Response.Write(e.Item.Cells[0].Text);
    }
    }

    When the button is command button is pressed, I am trying to read the text
    in the first cell (e.Item.Cells[0].text), but nothing is showing up. I do
    see that it recognizes eItem.Cells.Count and shows the number of cells as
    expected. But I do I read the contents of the cell in that row?

    PS: I don't have Visual Studio 03 installed. Could this be a bug?


    David Guest

  2. Similar Questions and Discussions

    1. DataGrid: How do I select and copy text for a DataGrid cell?
      Hi, Do you know how do I select and copy txt from a cell inside a Flex 2 DataGrid? I don't want to use an itemRenderer. I will appreciate...
    2. Programmatically Change Text Property of Label in ItemTemplate in Datagrid
      How do I programmatically change the text property of a label in an ItemTemplate in a datagrid? Specifically the Text property. I want to change...
    3. wrapping text in a datagrid cell
      I have a datagrid that I am having text wrapping problems with. And the wrapping problems only happen with text containing long urls. If I set...
    4. --- retrieving text from a selected datagrid cell ---
      this was working Dim szMsgNumber = db_grid.SelectedItem.Cells(0).Text until i changed the first column (at index 0) to a ASP:ButtonColumn...
    5. Can't read the content of a cell programmatically
      In the event handler for ItemCommand, I am trying to read text of cells in the row programmatically, but can't get it working. //this is what I...
  3. #2

    Default Re: datagrid: can't get read text from a cell programmatically

    Here is a follow up comment.

    I can set the text, and read what I set, but still can't read what is
    initially there. What is going on here?????


    //this line shows nothing. Why? The text is there.
    Response.Write(e.Item.Cells[0].Text);

    //this line will set the text of the first cell to "Good"
    e.Item.Cells[0].Text="Good";

    //And this line outputs "Good"
    Response.Write(e.Item.Cells[0].Text);


    David Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139