We help IT Professionals succeed at work.

Changing the text on a SelectText Button on a GridView control

mrnmnew
mrnmnew asked
on
Medium Priority
333 Views
Last Modified: 2013-11-07
I have a GridView which shows records from a database. The first column of this has on every row a button so the user can select an item to request a quote by email.

I need to change this text as the site is being converted to multi lingual and the text is fed from a database via an other GridView control on the Page_init event with something like:

Button1.Text = GridText.Rows.Item(0).Cells(53).Text

Any ideas how I can change this text as 'selecttext' doesn't seem to be an exposed property.

<Columns>
                <asp:CommandField ShowSelectButton="True" ButtonType="Button" HeaderText="Click to ask for a Quote" SelectText="Quote Me"  >
       
                </asp:CommandField>
 
...ect...

Open in new window

Comment
Watch Question

Use the Button Field as below. Replace <Column_Name_Of_Data_Source> with the column name of the data source from which you get the Text value.

add an event as,
protected void KOGrid_RowCommand(Object sender, GridViewCommandEventArgs e) {
   if (e.CommandName == "QuoteME" && e.CommandArgument != null) {
        // Do required
   }
}
<asp:ButtonField AccessibleHeaderText="Grouping" ButtonType="Button" HeaderText="Click to ask for a Quote" ShowHeader="True" CommandName="QuoteME" Text="<%# DataBinder.Eval(Container, "<Column_Name_Of_Data_Source>")%>">
	<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Wrap="False" />
</asp:ButtonField>

Open in new window

Author

Commented:
Almost there, thanks. But I prob was not clear in my initial description: The GridView with the button on that I want to change the text is a different Gridview with the text values depending on the language selected for the web site.

So Databinder.eval(container.dataitem"QuoteCol") doesn't reference the correct object as it is in the first GridView and not the one with the text translations in.

You need to use the Culture information for the page.  But before that, the Text value that you intend to show on the Button should also be the required character set (I mean, it should come in the form of language characters you desire) and based on the culture info, it will be displayed.
Refer these links too.
http://www.codeproject.com/KB/aspnet/ChangeCultures.aspx
http://msdn.microsoft.com/en-us/library/bz9tc508.aspx

Author

Commented:
I can't even get it to build without errors. I don't think it has anything to do with character sets as it will not even read the english version of the text
Ah! it seems that this is a different problem altogether.

Author

Commented:
The code

Text="<%# DataBinder.Eval(Container, "<Column_Name_Of_Data_Source>")%>
 I replaced with

Text="<%# DataBinder.Eval(Container, "Quote Me")%>

Quote Me being the column name in the gridview called gridtext
But as this button has to be in a column in the Gridview called GridView1 I suspect that it is looking in the wrong Container.

Is this correct ?
That is correct.  In that case, if the [Quote Me] has a common value then store it in a public variable and assign it to the button in the desired gridview.

Author

Commented:
Could you show me come code to do that, preferably in VB please ?
Dim QuoteMe As String as a page level public variable, where it will be accessed throughout your code.

Then, when the OnRowDataBound fires for the first gridview, get the text for QuoteMe from any of the row's cells, as you say they have common value.  Use this public QuoteMe to assign it to the Button's Text.

Actually, this is not the best way to do.  Have a function that returns the desired linguistic characters based on some input and use that to display it as Button's Text.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.