ASP中 双击左边的gridview的某一行 将数据添加到另一个gridview
同一页面有左右两个gridview 怎样实现双击左边的gridview某一行 将这一行的数据添加到右边的的gridview
请给具体代码
------解决方案--------------------参考:
http://www.cnblogs.com/insus/p/3211017.html
------解决方案--------------------我个人的做法是在gridview1里面先定义事件GridView1_RowDataBound 和GridView1_RowCommand,你懂的这个吧!
在用boundfield把数据库中的列与gridview绑定,然后 在itemtemplate里面定义一个隐藏的button,
<ItemTemplate>
<asp:Button ID="btnHiddenPostButton" CommandName="HiddenPostButtonCommand" runat="server" Text="HiddenPostButton" style="display:none"/>
</ItemTemplate>
最后在codebehind里写那两个事件,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//这里主要是主要是定义行单击事件,已经鼠标在行上时 颜色的改变等:
Button btnHiddenPostButton = e.Row.FindControl("btnHiddenPostButton") as Button;
if (btnHiddenPostButton != null)
{
e.Row.Attributes["onclick"] = String.Format("javascript:document.getElementById('{0}').click()", btnHiddenPostButton.ClientID);
e.Row.Attributes["onmouseover"] = "javascript:this.style.background='red'";
e.Row.Attributes["onmouseout"] = "javascript:this.style.background=''";
e.Row.Attributes["style"] = "cursor:pointer";
e.Row.Attributes["title"] = "Click for selecting this row and will show the ExceptionInstance at the bottom of the page!";
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
// 这里是在第一个gridview里单击传递参数,并根据这个参数绑定数据到第二个gridview
GridViewRow row = null;
switch (e.CommandName)
{
case "HiddenPostButtonCommand":
Control cmdControl = e.CommandSource as Control;
row = cmdControl.NamingContainer as GridViewRow;
Session["ajk"] = row.Cells[1].T