?
Solved

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

Posted on 2010-09-22
5
Medium Priority
?
518 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

777 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