Re: Accessing the text in a cell of a gridview control

Discussion in 'ASP .Net' started by James Irvine, Jan 17, 2007.

  1. James Irvine

    James Irvine Guest

    "Randy" <> wrote in message
    news:...
    > SPecifically in the gridview_RowDeleting , in the gridview__RowDataBound I
    > use e.Row.Cells(0).Text but those do not appear in the intellisense in the
    > RowDeleting event.
    >
    > "Randy" wrote:
    >
    >> Hi,
    >> In the old datagrid control in VS2003 the text in a cell could be
    >> accessed
    >> by using the following sysntax:
    >> e.Item.Cells(1).Text
    >>
    >> What is the Corresponding code to access the text in a cell of a new
    >> gridview control?
    >>
    >> Thanks for any help



    Does this help?

    protected void DetailsView1_ItemInserting(object sender,
    DetailsViewInsertEventArgs e)

    {

    string newcat = (string)e.Values["catA"];


    if ((newcat == null) || (newcat == ""))

    {

    LabelFeedback.Text = "Please enter a new category to insert";

    e.Cancel = true;

    return;

    }

    // check if this insert already exists:

    // 1. copy the items in the Rows collection into an array.

    GridView gv = GridView1;

    int idx = gv.SelectedIndex;

    GridViewRow gvw = gv.SelectedRow;

    GridViewRow[] rowArray = new GridViewRow[gv.Rows.Count];

    gv.Rows.CopyTo(rowArray, 0);

    // 2. iterate though the array and display the value in the first cell of
    the row.

    int j = -1;

    foreach (GridViewRow row in rowArray)

    {

    j++;

    if (newcat == row.Cells[2].Text)

    {

    LabelFeedback.Text = "This category already exists";

    e.Cancel = true;

    break;

    }

    }

    // if all ok to go, insert the trimmed value:

    e.Values["catA"] = newcat;

    }
     
    James Irvine, Jan 17, 2007
    #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. =?Utf-8?B?QmFzcyBQcm8=?=

    Accessing textbox control in a table cell

    =?Utf-8?B?QmFzcyBQcm8=?=, May 18, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    4,193
    =?Utf-8?B?QmFzcyBQcm8=?=
    May 19, 2005
  2. news.rcn.com
    Replies:
    1
    Views:
    9,780
    Chris Smith
    Jul 12, 2004
  3. mark4asp
    Replies:
    0
    Views:
    468
    mark4asp
    Jan 18, 2007
  4. LamSoft
    Replies:
    5
    Views:
    432
    LamSoft
    Jun 14, 2007
  5. S_K
    Replies:
    1
    Views:
    3,681
    Yankee Imperialist Dog
    Jun 5, 2008
Loading...

Share This Page