如何实现 双击 GridView 单元格编辑单元格内容

thycloud03 2009-08-28 02:07:36
    
<asp:GridView ID="GV_Humiture" runat="server"
Height="10px" Width="100%" AutoGenerateColumns="False" OnRowDataBound="GV_Humiture_RowDataBound" OnRowCreated="GV_Humiture_RowCreated" BackColor="White" CssClass="font11" BorderColor="#ABC5E0" >
<FooterStyle BackColor="White" ForeColor="#001F42" BorderColor="#ABC5E0" BorderWidth="1px" />
<Columns>
<asp:BoundField DataField="Date" HeaderText="日期" >
<HeaderStyle BorderColor="#001F42" Font-Bold="False" />
<ItemStyle ForeColor="#001F42" Width="6%" />
</asp:BoundField>
<asp:BoundField DataField="am_Dry" HeaderText="干(℃)" >
<ItemStyle ForeColor="#001F42" Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="am_Wet" HeaderText="湿(℃)" >
<ItemStyle ForeColor="#001F42" Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="am_Humidity" HeaderText="相对湿度(%)" >
<ItemStyle ForeColor="#001F42" Width="19%" />
</asp:BoundField>
<asp:BoundField DataField="pm_Dry" HeaderText="干(℃)" >
<ItemStyle ForeColor="#001F42" Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="pm_Wet" HeaderText="湿(℃)" >
<ItemStyle ForeColor="#001F42" Width="12%" />
</asp:BoundField>
<asp:BoundField DataField="pm_Humidity" HeaderText="相对湿度(%)">
<ItemStyle ForeColor="#001F42" Width="19%" />
</asp:BoundField>
<asp:BoundField DataField="Note" HeaderText="备注" >
<ItemStyle ForeColor="#001F42" Width="7%" />
</asp:BoundField>
</Columns>
<AlternatingRowStyle BorderColor="#001F42" ForeColor="#001F42" />
<RowStyle Font-Names="Arial" ForeColor ="#ABC5E0" />
</asp:GridView>


怎么实现双击 GridView (GV_Humiture) 单元格后可以编辑单元格内容.


...全文
1708 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2009-08-28
  • 打赏
  • 举报
回复
protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow Row in GridView1.Rows)
{
if (Row.RowType == DataControlRowType.DataRow)
{
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Edit$" + Row.RowIndex.ToString(), true);
Row.Attributes["style"] = "cursor:pointer";
Row.Attributes["title"] = "双击进入编辑";
if (Row.RowState == DataControlRowState.Edit)
{
Row.Attributes.Remove("ondblclick");
Row.Attributes.Remove("style");
Row.Attributes["title"] = "编辑行";
for (Int32 i = 1; i < GridView1.Columns.Count; i++)
{
((TextBox)Row.Cells[i].Controls[1]).Attributes.Add("onmouseover", "this.select()");
}
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Update$" + Row.RowIndex.ToString(), true);

}
for (int i = 1; i < Row.Cells.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(Row.UniqueID + "$ctl00", i.ToString());
}
}
}
base.Render(writer);
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
BindData();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//更新数据
}
参考
  • 打赏
  • 举报
回复

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow Row in GridView1.Rows)
{
if (Row.RowType == DataControlRowType.DataRow)
{
//双击进入编辑模式
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Edit$" + Row.RowIndex.ToString(), true);
Row.Attributes["style"] = "cursor:pointer";
Row.Attributes["title"] = "双击进入编辑";
if (Row.RowState == DataControlRowState.Edit)
{
Row.Attributes.Remove("ondblclick");
Row.Attributes.Remove("style");
Row.Attributes["title"] = "编辑行";
for (Int32 i = 1; i < GridView1.Columns.Count; i++)
{
((TextBox)Row.Cells[i].Controls[1]).Attributes.Add("onmouseover", "this.select()");

}
//双击更新
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Update$" + Row.RowIndex.ToString(), true);

}
//
for (int i = 1; i < Row.Cells.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(Row.UniqueID + "$ctl00", i.ToString());
}
}
}
base.Render(writer);
}
  • 打赏
  • 举报
回复

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow Row in GridView1.Rows)
{
if (Row.RowType == DataControlRowType.DataRow)
{
//双击进入编辑模式
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Edit$" + Row.RowIndex.ToString(), true);
Row.Attributes["style"] = "cursor:pointer";
Row.Attributes["title"] = "双击进入编辑";
if (Row.RowState == DataControlRowState.Edit)
{
Row.Attributes.Remove("ondblclick");
Row.Attributes.Remove("style");
Row.Attributes["title"] = "编辑行";
for (Int32 i = 1; i < GridView1.Columns.Count; i++)
{
((TextBox)Row.Cells[i].Controls[1]).Attributes.Add("onmouseover", "this.select()");

}
//双击更新
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Update$" + Row.RowIndex.ToString(), true);

}
//
for (int i = 1; i < Row.Cells.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(Row.UniqueID + "$ctl00", i.ToString());
}
}
}
base.Render(writer);
}
  • 打赏
  • 举报
回复

protected override void Render(HtmlTextWriter writer)
{
foreach (GridViewRow Row in GridView1.Rows)
{
if (Row.RowType == DataControlRowType.DataRow)
{
//双击进入编辑模式
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Edit$" + Row.RowIndex.ToString(), true);
Row.Attributes["style"] = "cursor:pointer";
Row.Attributes["title"] = "双击进入编辑";
if (Row.RowState == DataControlRowState.Edit)
{
Row.Attributes.Remove("ondblclick");
Row.Attributes.Remove("style");
Row.Attributes["title"] = "编辑行";
for (Int32 i = 1; i < GridView1.Columns.Count; i++)
{
((TextBox)Row.Cells[i].Controls[1]).Attributes.Add("onmouseover", "this.select()");

}
//双击更新
Row.Attributes["ondblclick"] = ClientScript.GetPostBackEventReference(GridView1, "Update$" + Row.RowIndex.ToString(), true);

}
//
for (int i = 1; i < Row.Cells.Count; i++)
{
Page.ClientScript.RegisterForEventValidation(Row.UniqueID + "$ctl00", i.ToString());
}
}
}
base.Render(writer);
}
24K純帥 2009-08-28
  • 打赏
  • 举报
回复
puzhichen 2009-08-28
  • 打赏
  • 举报
回复
百度一下:
GridView72般绝技
里面有N多例子!!!
ivws_19 2009-08-28
  • 打赏
  • 举报
回复
// 获得行索引
int _rowIndex = int.Parse(e.CommandArgument.ToString());
// 解析事件参数(在RowDataBound中增加的),从而获得被选中的列的索引
int _columnIndex = int.Parse(Request.Form["__EVENTARGUMENT"]);
// 设置GridView被选中的行的索引(每次回发后判断GridView1.SelectedIndex > -1则更新)
_gridView.SelectedIndex = _rowIndex;
_gridView.DataBind();

// 获得被选中单元格的显示控件并设置其不可见
Control _displayControl = _gridView.Rows[_rowIndex].Cells[_columnIndex].Controls[..];
_displayControl.Visible = false;
// 获得被选中单元格的编辑控件并设置其可见
Control _editControl = _gridView.Rows[_rowIndex].Cells[_columnIndex].Controls[..];
_editControl.Visible = true;
thycloud03 2009-08-28
  • 打赏
  • 举报
回复
RowCommand中怎么写 问题是如何实现双击的那个单元格变成文本框
cyrix_wxm 2009-08-28
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090212/09/fe420554-3d4f-49e0-9243-d025eb03c149.html
candybaobao 2009-08-28
  • 打赏
  • 举报
回复
关注。。。
ivws_19 2009-08-28
  • 打赏
  • 举报
回复
<Columns>
<asp:ButtonField Text="DoubleClick" CommandName="DoubleClick"
Visible="false" />
</Columns>
rowdatabound中:
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton _doubleClickButton = (LinkButton)e.Row.Cells[1].Controls[0];
string _jsDouble = ClientScript.GetPostBackClientHyperlink(_doubleClickButton, "");
e.Row.Attributes["ondblclick"] = _jsDouble;
}

然后在RowCommand中判断CommandName
王者coco 2009-08-28
  • 打赏
  • 举报
回复
up
plglenn9 2009-08-28
  • 打赏
  • 举报
回复
d
thycloud03 2009-08-28
  • 打赏
  • 举报
回复
<asp:TemplateField>
<ItemTemplate >
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("InfManageID", "~/Web/InfManage/InfManageSee.aspx?InfManageID={0}") %>'
Text='<%# Eval("Title") %>' Target="_blank"></asp:HyperLink>
<asp:Image ID="ImageNew" runat="server" visible="false" Width="25" Height="10" />
<asp:HiddenField ID="HF_ContentOrLink" runat="server" value='<%# Eval("ContentOrLink") %>'/>
</ItemTemplate>
<ItemStyle Width="80%" />
</asp:TemplateField>


<%# Eval("Title") %>' 使用这个绑定 难道 非得 DataSourceID="SqlDataSource1" 不能直接从后台给定一个DT 绑定吗?
bychgh 2009-08-28
  • 打赏
  • 举报
回复
帮顶
thycloud03 2009-08-28
  • 打赏
  • 举报
回复
onDblClick 后怎么办 ........ 关键部分省略 你真高
ivws_19 2009-08-28
  • 打赏
  • 举报
回复
RowDataBound事件中
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.attributs.add("onDblClick", "...")
wiki14 2009-08-28
  • 打赏
  • 举报
回复
http://topic.csdn.net/u/20090212/09/fe420554-3d4f-49e0-9243-d025eb03c149.html


一、表头表尾 1、自定义多行表头,列合并,行合并 2、删除表身指定列、行 3、固定表头,向下拉动滚动条时,表头固定不动 4、表脚行统计,总计、平均值 二、导入导出 1、导出Excel,Word 2、导入Excel 三、多层嵌套 1、在父GridView中的编辑模板中嵌套一个子GridView 2、三层GridView嵌套 四、分页排序 1、分页 2、列排序,点击列升序、降序排序 五、结合控件 1、CheckBox控件,多选、全选 2、DropDownList控件 3、隐藏控件,当选择处理状态选中备注时,隐藏textbox显示 4、radio控件,选中获取GridView表主键 5、GridView中DropDownList绑定数据,直接绑定显示,无需点击编辑按纽。 6、JavaScript操作checbox实现全选,多选 六、设置属性 1、JavaScript设置GridView行的背景颜色,单偶行的背景颜色,鼠标停留行背景,鼠标选中时的行背景 2、GridView的JavaScript中的行单击,双击、删除提示框、快捷键事件 3、GridView设置属性,单元格文本颜色,单元格背景颜色,表中增加空行 七、无代码 GridView排序、发送邮件、点击行查看详情,内容过长截取 八、选增删改 1、GridView自带的选中、编辑、删除,即CommandField 2、GridView添加记录,在GridView表脚添加控件,用添加记录 3、更新所有记录,GridView直接绑定控件,然后更新 九、主键索引 根据主键多条记录删除,单条记录删除。

62,047

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧