GridView and ButtonField type

J

jhaidon

Hi everybody,

I want to fill in a GridView with a dataset.
So I created the list of fields that I want to see in the gridview.
And I added a column (in first position in the gridview) as a
ButtonField column (ButtonType: button).
My records are loaded correctly.
During the RowDataBound event, I tried to change the Text of the button
for some records (depends of a check on others cells).

if (e.Row.Cells[12].Text == var.ToString())
e.Row.Cells[0].Text = "Cancel";
else
e.Row.Cells[0].Text = "Accept";

When I keep this check (and set), the text is changed, perfect.
But the type of my button is also changed.
That become a link type (ButtonType: link) and no more a "button" type.

Why ?
I don't understand what's happening :-{

If I don't perform my check (and set), the type of my ButtonField stays
"button".

Do you have a idea of what is wrong ?
Thanks in advance
Jerome

PS: I use the framework 2.0 (and VS2005).
 
J

Jan Hyde

(e-mail address removed)'s wild thoughts were released on 30 Apr
2006 11:14:01 -0700 bearing the following fruit:
Hi everybody,

I want to fill in a GridView with a dataset.
So I created the list of fields that I want to see in the gridview.
And I added a column (in first position in the gridview) as a
ButtonField column (ButtonType: button).
My records are loaded correctly.
During the RowDataBound event, I tried to change the Text of the button
for some records (depends of a check on others cells).

if (e.Row.Cells[12].Text == var.ToString())
e.Row.Cells[0].Text = "Cancel";
else
e.Row.Cells[0].Text = "Accept";

When I keep this check (and set), the text is changed, perfect.
But the type of my button is also changed.
That become a link type (ButtonType: link) and no more a "button" type.

Why ?
I don't understand what's happening :-{

If I don't perform my check (and set), the type of my ButtonField stays
"button".

Do you have a idea of what is wrong ?

You most likely need to change the text of the button not
the cell. I'm not sure how you'd achieve this if the button
is automatically generated but should be easy if you change
it to a template field.





Jan Hyde (VB MVP)
 
J

jhaidon

Hi,
I found the solution.
I need to get the first control of my first cell. It's my button field.

Button myButton = null;
myButton = (Button)e.Row.Cells[0].Controls[0];
myButton .Text = "Cancel";

Jerome
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top