Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GridView: Change selected row THEN select a control in that row

Posted on 2010-09-22
5
Medium Priority
?
519 Views
Last Modified: 2013-12-16
Using Visual Studio 2008...In a GridView, I want to click on a control (textbox) of a non-selected row and have THAT row become selected AND give focus to the control that was clicked. I can get this code to select the row:
e.Row.Cells[colseqClientName].Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.GridViewSearchResults, "Select$" + e.Row.RowIndex);

But, I haven't figured out how to subsequently give the clicked textbox focus.
Is that possible?
(The GridView data is supplied by a SQL datasource. My coding options are: C# and javascript.)

Thanks,

-Ron
0
Comment
Question by:RonCoderre
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 41

Assisted Solution

by:guru_sami
guru_sami earned 2000 total points
ID: 33736096
You can try doing that in GridView SelectedIndexChanged event:

protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox tb = (TextBox)GridView1.SelectedRow.FindControl("txtABCD");
        if (tb != null)
        {
            tb.Focus();
        }
    }
0
 
LVL 2

Author Comment

by:RonCoderre
ID: 33736443
Thanks for replying, guru_sami

The gridview row has many fields, many with textboxes and I don't know which will be selected before the code runs.

Example:
If row_10 is selected and a user clicks the BillingPerson textbox on row_4,
I want row_4 selected THEN the BillingPerson textbox on row_4 to receive the focus.

Upon clicking a textbox, perhaps there's a way to:
• store the clientID of the selected textbox
• Select the gridview row that contains the selected textbox (that action removes the focus from the textbox)
• Re-select the textbox from the stored clientID

I haven't found a way to combine this C# code:
ClientScript.GetPostBackClientHyperlink(this.GridViewSearchResults, "Select$" + e.Row.RowIndex);
with the javascript that assigns focus to a control:
document.getElementById(controlID).focus();
and hook that combination to the onClick event of the textbox (or anyplace else...as long as the end result is the same)
0
 
LVL 41

Accepted Solution

by:
guru_sami earned 2000 total points
ID: 33738963
Ok I see what you mean but don't know exact solution.
What I think is even if you set that in javascript, the PostBack is going to reset it.
Not sure but see if using AJAX in someway helps.
0
 
LVL 2

Author Comment

by:RonCoderre
ID: 33740347
I stumbled upon some code that looks very promising.
I partially implemented it today and it seems to be getting me most of the way to where I want to be.
I'll finish the implementation tomorrow and see if I can tie up the loose ends.
If it works I'll post the solution.

(BTW...I already am using AJAX)
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question