在行的双击上以编辑模式打开gridview [英] Open gridview in edit mode on row's doubleclick

查看:89
本文介绍了在行的双击上以编辑模式打开gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在editmode上获取网格视图,因为我必须提到下面提到的重要内容



=> 添加属性doubleclick



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



=> 编辑网格视图

protected void grdvmovies_RowEditing(object sender,GridViewEditEventArgs e)



{



grv1.EditIndex = e.NewEditIndex; < br $>


}



但我如何结合在一起意味着我想在行上添加一个Gridview编辑事件处理程序双击属性,但我无法添加它。

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.

推荐答案

根据您的要求,我认为没有任何内置功能来实现它。但是,您可以使用javascript并创建自定义解决方案。以下步骤将给你一个想法。修改代码并试一试。不要使用自动更新和添加记录。



1)在gridview下方或上方添加一行,其中包含带有标签的可编辑字段(文本框和其他控件)( lblSelectedRecord)显示记录ID和两个按钮(btnUpdate& btnCancel)

2)在您的aspx页面上添加按钮(不会显示在页面上):

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:button runat="server" id="btnHDN" style="display:none" onclick="btnHDN_Click" xmlns:asp="#unknown" />



3)在gridview的第0列添加一个带有文本作为记录ID的不可见标签(lblRecordID),并将此代码添加到OnRowDataBound事件中。


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.

Label lbl = new Label();
lbl = (Label)e.Row.FindControl("lblRecordID");
e.Row.Attributes.Add("ondblclick","selectRow('"+lbl.Text.Trim()+"')");



4)在您的aspx页面中添加javascript:


4) Add javascript in your aspx page:

function selectRow(rowId)
{
document.getElementById("lblSelectedRecord").value = rowId;
__doPostBack("btnHDN","");
}





在您的代码隐藏写作中:





In your code-behind write:

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





5)在btnUpdate_Click事件中写入更新功能并取消btnCancel_Click事件中的功能

6)重新绑定你的gridview。

7)在未经测试的情况下对代码进行调整。它只是随机写的。



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.






在双击事件中获取行id并在该事件中设置



grv1.EditIndex = e.NewEditIndex;
Hi,

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

grv1.EditIndex = e.NewEditIndex;


这篇关于在行的双击上以编辑模式打开gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆