日期:2014-05-19  浏览次数:20867 次

直接在datagrid上操作数据
想实现datagrid里某个单元格,点击右键跳出查询,修改,删除等...
如果选择查询则跳出一个对应该字段为查询条件的窗口,实现查询功能..
分不多,请达人附个源码.

------解决方案--------------------
很好实现吧!
DataGridView_Click()
{
if (e.button==button.right)
{
if(datagridview.columnsindex==2)
{
menu.show();
}
}

menu_click()
{
switch(type)
{
case "delete ":
....
break;
case "insert ":
....

}
}
}


最后用sqldataadapter.update(dt)更新数据

------解决方案--------------------
<%@ Page language= "c# " Codebehind= "WebForm1.aspx.cs " AutoEventWireup= "false " Inherits= "shiyan.WebForm1 " %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN " >
<HTML>
<HEAD>
<title> WebForm1 </title>
<meta name= "GENERATOR " Content= "Microsoft Visual Studio .NET 7.1 ">
<meta name= "CODE_LANGUAGE " Content= "C# ">
<meta name= "vs_defaultClientScript " content= "JavaScript ">
<meta name= "vs_targetSchema " content= "http://schemas.microsoft.com/intellisense/ie5 ">
<script type= "text/javascript ">
function oClick(layer)
{
if(event.button==2)
{
var e = document.getElementById( "menu ");
e.style.left = event.clientX;
e.style.top = event.clientY;
e.style.visibility = "visible ";

var i = layer.id.indexOf( "td_ ");
var j = layer.id.indexOf( "- ");
document.getElementById( "put_orderID ").value = layer.id.substr(i+3,j-i-3);
document.getElementById( "put_col ").value = layer.id.substr(j+1);
}
}
function over(layer)
{
layer.style.backgroundColor= "#00ccff ";
}
function out(layer)
{
layer.style.backgroundColor= "#ffffff ";
}
</script>
</HEAD>
<body>
<form id= "Form1 " method= "post " runat= "server ">
<table id= "menu " cellpadding= "2 " cellspacing= "0 " bgcolor=#ffffff oncontextmenu= "self.event.returnValue=false " onmousedown= "if(event.button==1)menu.style.visibility= 'hidden '; " style= "cursor: pointer; Z-INDEX: 2; WIDTH: 100px; POSITION: absolute; visibility: hidden; font-size:13px; BORDER-RIGHT: #cccccc 1px solid; BORDER-TOP: #cccccc 1px solid; BORDER-LEFT: #cccccc 1px solid; BORDER-BOTTOM: #cccccc 1px solid ">
<tr>
<td onmouseover= "over(this) " onmouseout= "out(this) "> 查询 </td>
</tr>
<tr>
<td onmouseover= "over(this) " onmouseout= "out(this) "> 修改 </td>
</tr>
<tr>
<td onmouseover= "over(this) " onmouseout= "out(this) "> 删除 </td>
</tr>
</table>
<div oncontextmenu= "self.event.returnValue=false " onmousedown= "if(event.button==1)menu.style.visibility= 'hidden '; ">
<asp:DataGrid id= "DataGrid1 " runat= "server "> </asp:DataGrid>
</div>
<input id=put_orderID type=text> <input id=put_col type=text>
</form>