Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: Accessing the text in a cell of a gridview control

Reply
Thread Tools

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

 
 
James Irvine
Guest
Posts: n/a
 
      01-17-2007

"Randy" <> wrote in message
news:E7C40CC6-7F4F-4C40-B723-...
> 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;

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Javascript to retrieve Gridview cell text Tony WONG ASP .Net 1 12-30-2009 06:26 AM
Retrieving GridView.Rows[x].Cells[y].text when cell ReadOnly isturned off S_K ASP .Net 1 06-05-2008 06:06 PM
How to get a text from a specified cell in the gridview? LamSoft ASP .Net 5 06-14-2007 08:25 AM
Re: Accessing the text in a cell of a gridview control mark4asp ASP .Net 0 01-18-2007 12:49 PM
How to set and highlight text in JTable cell on selection and/or invoke cell editor directly. news.rcn.com Java 1 07-12-2004 10:22 PM



Advertisments