Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a gridview with some textboxes in editable form, when user clicks on a perticular Textbox. I want to highlight the row which contains that text box.
How can I do this using Jquery or javascript Please advice.
Posted

 
Share this answer
 
Comments
pinky1810 20-Dec-12 3:37am    
Thanks, I tried your solution in this way but not working

protected void GridviewSample_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] =
"javascript:setMouseOverColor(this);";
e.Row.Attributes["onmouseout"] =
"javascript:setMouseOutColor(this);";
e.Row.Attributes["onclick"] =
ClientScript.GetPostBackClientHyperlink
(this.GridviewSample, "Select$" + e.Row.RowIndex);
}
and design code.

<script type="text/javascript">
var oldgridSelectedColor;

function setMouseOverColor(element) {
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor = 'yellow';
element.style.cursor = 'hand';
element.style.textDecoration = 'underline';
}

function setMouseOutColor(element) {
element.style.backgroundColor = oldgridSelectedColor;
element.style.textDecoration = 'none';
}
</script>


<asp:GridView ID="GridviewSample" runat="server" AutoGenerateColumns="false"
onselectedindexchanged="GridviewSample_SelectedIndexChanged"
onselectedindexchanging="GridviewSample_SelectedIndexChanging"
ondatabound="GridviewSample_DataBound" >

<columns> <asp:BoundField DataField="SNo" HeaderText="SNo" />

<asp:TemplateField HeaderText="Name">
<itemtemplate>
<asp:TextBox ID="txtname" runat="server" >




<asp:Button ID="BtnSave" runat="server" onclick="BtnSave_Click" Text="Save" />
<asp:TextBox ID="TextBox1" runat="server">

Is it right, please advice
Hi,
Asuming that the text box is under tr -> td -> textbox, you may try the following JQuery:

$("#GridViewId input[type=text]").focus(function () {
         $(this).parent().parent().css('background-color', 'red');
    });
 
Share this answer
 
Comments
pinky1810 20-Dec-12 3:33am    
can u give me a sample for this please, I am new to this.I dont know how to use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900