ASP中 双击左边的gridview的某一行 将数据添加到另一个gridview,该怎么解决
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].Text;
SqlConnection con = new SqlConnection("你的con语句,自己写吧");
string query = string.Format("select * from****** ", Session["ajk"]));
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "exp");
GridView2.DataSource = ds.Tables["exp"];
GridView2.DataBind();
break;
}
}
大概就是这样的一个思路,你可以根据自己的程序改一下! GOOD LUCK. Hopefully it is helpful to you.
------解决方案--------------------
此楼已经详解步骤,看仔细的话可以解决楼主大部分问题了
同一页面有左右两个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].Text;
SqlConnection con = new SqlConnection("你的con语句,自己写吧");
string query = string.Format("select * from****** ", Session["ajk"]));
SqlDataAdapter da = new SqlDataAdapter(query, con);
DataSet ds = new DataSet();
da.Fill(ds, "exp");
GridView2.DataSource = ds.Tables["exp"];
GridView2.DataBind();
break;
}
}
大概就是这样的一个思路,你可以根据自己的程序改一下! GOOD LUCK. Hopefully it is helpful to you.
------解决方案--------------------
此楼已经详解步骤,看仔细的话可以解决楼主大部分问题了