Click here to Skip to main content
15,896,154 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to take grid view on editmode for this i have to important things as i mention below

=>Add attribute doubleclick:

e.Row.Attributes.Add("ondblclick", "Javascript:__doPostBack('myDblClick','" + e.Row.RowIndex + "');");

=>And for edit a gridview
protected void grdvmovies_RowEditing(object sender, GridViewEditEventArgs e)

{

grv1.EditIndex = e.NewEditIndex;

}

But how i can combine together mean i want to add a Gridview edit event handler on row double click attribute but i am unable to add on it.
Posted

As your requirement demands, I don't think there is any inbuilt functionality to achieve it. However, you can play with javascript and create your custom solution. Following steps willl give you an idea. Modify the code and give it a try. Do not use auto update and addition of records.

1) Add a row below or above your gridview with the editable fields (textboxes and other controls) with a lable (lblSelectedRecord) to show Record ID and two buttons (btnUpdate & btnCancel)
2) Add Button(which will not be displayed on the page) on your aspx page as:
ASP.NET
<asp:button runat="server" id="btnHDN" style="display:none" onclick="btnHDN_Click" xmlns:asp="#unknown" />

3) Add a invisible label(lblRecordID) with text as record ID at 0th column of your gridview and add this code inside the "OnRowDataBound" event.
C#
Label lbl = new Label();
lbl = (Label)e.Row.FindControl("lblRecordID");
e.Row.Attributes.Add("ondblclick","selectRow('"+lbl.Text.Trim()+"')");

4) Add javascript in your aspx page:
JavaScript
function selectRow(rowId)
{
document.getElementById("lblSelectedRecord").value = rowId;
__doPostBack("btnHDN","");
}


In your code-behind write:

C#
protected void btnHDN_Click(object sender, EventArgs e)
{
string _recordId = lblSelectedRecord.Text.Trim(); 
//your code to fill the details of the selected record
}


5) Write update functionality in btnUpdate_Click event and cancelling functionality in btnCancel_Click event
6) Re-bind your gridview.
7) Make adjustments to the code as it is not tested. It is just randomly written.
 
Share this answer
 
Hi,

On your double click event get the row id and in that event set the

grv1.EditIndex = e.NewEditIndex;
 
Share this answer
 
Comments
maheshbisht 2-Jan-13 6:57am    
Hello Sir did u ever try this on adding attribute, it's useless.

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