473,320 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Getting at buttonField text in a gridview

I have a button field in a gridview defined as follows:
<asp:ButtonField ButtonType="Button"
CommandName="AcceptOrder" Text="Accept Whole Order">
<ControlStyle Font-Size="X-Small" />
</asp:ButtonField>

In the RowCommand event I have the following code:
if ((string)e.CommandName.ToLower() == "acceptorder")
{
int myRow = int.Parse(e.CommandArgument.ToString());
WebControl myBF =
(WebControl)gvOrders.Rows[myRow].Cells[acceptbutton].Controls[0];

I'm trying to get ahold of the control to test for what the text value is.
When myBF is displayed in the watch window it value is { Text="Accept Whole
Order }

But, I can't find that text value anywhere in the object. There is not text
values anywhere.

How can I find the text (and change it)?

--
Regards,
Gary Blakely
Dean Blakely & Associates
www.deanblakely.com
Feb 17 '07 #1
3 22500
Hello Gary,

As for ButtonField, since it has been well encapsulated and the internal
control structure and naming rule is not documented, it will be
inconvenient to access nested controls in it.(We have to rely on control
index which is always not safe). I would always recommend you consider
converting it to template field if possible.

If you do need to access the Button and property values of the inner button
of ButtonField, you can use the control index. One means I usually use is
turn on the trace on page and view the control structure on the page, this
will help detect the correct control hierarchy on ASP.NET page.

For the Button instance, it is of "DataControlButton" or
"DataControlLinkButton" type based on the "ButtonType" you configured in
the ButtonField. You can simply use their super class(Button and
LinkButton) to reference them. Here is some code snippet demonstrate on
this:
==============================
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs
e)
{
if (e.CommandName == "MyCommand")
{
Response.Write("<br/>Argument: " + e.CommandArgument + ",
source: " + e.CommandSource);

int index = int.Parse((string)e.CommandArgument);

Control control = GridView1.Rows[index].Cells[3].Controls[0];
string text = string.Empty;
if (((ButtonField)GridView1.Columns[3]).ButtonType ==
ButtonType.Link)
{
LinkButton btn = control as LinkButton;
text = btn.Text;
}
else
{
Button btn = control as Button;
text = btn.Text;
}
Response.Write("<br/>control: " + text);

}
}
====================================

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 19 '07 #2
Steven,
It turns out that if I just cast it as a "Button" everything works fine
because myButton.text has the text.

--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:4T**************@TK2MSFTNGHUB02.phx.gbl...
Hello Gary,

As for ButtonField, since it has been well encapsulated and the internal
control structure and naming rule is not documented, it will be
inconvenient to access nested controls in it.(We have to rely on control
index which is always not safe). I would always recommend you consider
converting it to template field if possible.

If you do need to access the Button and property values of the inner
button
of ButtonField, you can use the control index. One means I usually use is
turn on the trace on page and view the control structure on the page, this
will help detect the correct control hierarchy on ASP.NET page.

For the Button instance, it is of "DataControlButton" or
"DataControlLinkButton" type based on the "ButtonType" you configured in
the ButtonField. You can simply use their super class(Button and
LinkButton) to reference them. Here is some code snippet demonstrate on
this:
==============================
protected void GridView1_RowCommand(object sender,
GridViewCommandEventArgs
e)
{
if (e.CommandName == "MyCommand")
{
Response.Write("<br/>Argument: " + e.CommandArgument + ",
source: " + e.CommandSource);

int index = int.Parse((string)e.CommandArgument);

Control control = GridView1.Rows[index].Cells[3].Controls[0];
string text = string.Empty;
if (((ButtonField)GridView1.Columns[3]).ButtonType ==
ButtonType.Link)
{
LinkButton btn = control as LinkButton;
text = btn.Text;
}
else
{
Button btn = control as Button;
text = btn.Text;
}
Response.Write("<br/>control: " + text);

}
}
====================================

Hope this helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Feb 22 '07 #3
Thanks for your followup Gary,

Yes, if your ButtonField is configured as "Push Button" style, you can cast
the button into a standard "Button" class instance since that is the super
class. Anyway, glad that you've made it working. If you have any further
questions, please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 22 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: JE | last post by:
Hi! I am snooping around all sorts of websites and faqs, in search of a way to pick up any selected (mouse-highlighted) text in a HTML page, and store it in a JavaScript variable. I have...
15
by: Aaron Gray | last post by:
<iframe name="iframe" width="100%" height="25%" src="test1.txt"> </iframe> <a href="test1.txt" target="input">one</a> <a href="test2.txt" target="input">two</a> <form name="form1"> <textarea...
10
by: fotzor | last post by:
Hi, I'm a C++-Programmer and want to subclass the Edit used to write a SQL-Query in Access. The edit is of the special Access class OKttbx. Everything works, I injected a DLL into the...
5
by: Hassan Bassam | last post by:
I am having a problem. How can I get the selected text from a text editor. I am using ASP.NET and VB as language. Thanx
1
by: Sathyaish | last post by:
How do you get the text of a ButtonColumn control column in a datagrid? As an example, I tried this little snippet on a test project, but it returns a null string. Private Sub...
4
by: Bob Greschke | last post by:
Hi! I want to grab the contents of a Text widget when the frame it's on gets destroyed. I tried TextWidget.bind("<Destroy>"... , but the widget is gone before the call gets made, and I'd really...
4
by: afrinspray | last post by:
Is there a way to get the selected text inside a div, or other element? Mike
0
by: gomzi | last post by:
hi, Isn't it possible to set the color of the text used for paging in gridview through css? am able to set the font format but not able to set the color. its possible to set the color through...
1
by: renatois | last post by:
Getting value from GridView Hi guys, I have a GridView and I need to access a value of an ID field on an event. I converted this field into template and the name of the label control in...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.