Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
I have a web page.
On that page there is a gridview and an edit button which is not inside the grid view.
Edit button is disabled on pageload.
I have enabled the select option of gridview by adding an attribute through javascript.

I want that button 'Edit' to be enabled on click of any row in gridview.

Following is code to enable row select in grid view.

C#
if (e.Row.RowType == DataControlRowType.DataRow)
          {
              e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(gvSearchResult, "Select$" + e.Row.RowIndex);
              //e.Row.Attributes.Add("onclick", "fnEnableButton();");
              e.Row.Attributes["style"] = "cursor:pointer";
          }


I also tried writing this code and enabling button in fnEnableButton() function.

e.Row.Attributes.Add("onclick", "fnEnableButton();");

But then the row select attribute is not applied.


-Akshay.
Posted
Updated 1-Apr-14 20:43pm
v2
Comments
jacobjohn196 2-Apr-14 3:08am    
Using radio button inside gridview for selecting row is easy.

try this:
e.Row.Attributes.Add("onclick", "javaScript: return fnEnableButton();");

You can get help from below links:
http://stackoverflow.com/questions/1420606/click-row-in-gridview[^]
http://stackoverflow.com/questions/11008952/clickable-grid-view-row-asp-net[^]
 
Share this answer
 
Comments
aks.shan 2-Apr-14 4:45am    
That doesnot work...Edit button is enabled but I dont get selected row index.
e.Row.Attributes.Add("onclick","return fnEnableButton("+e.Row.RowIndex+")");


//In the fnEnableButton function in javascript get object of row and display it in selected mode .

function fnEnableButton(rowNum)
{
var ogv=document.getElementById("gvid");
var rowObj=ogv.rows[rowNum];
//now highlight the row and also enable the button .
}

Note: This code is not tested . Hope this will be helppful.
Rgrds
Lok
I follow
c# interview questions and answers [^] for testing my C# technical skills .
 
Share this answer
 
v2

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