在GridView中潜套一个层,点击‘ 打开‘ 展开此层,反之
所用到的JavaScript如下:
< script type = " text/javascript " >
// <![CDATA[
function ShowHidden(sid,ev)
{
ev = ev || window. event ;
var target = ev.target || ev.srcElement;
var oDiv = document.getElementById( " div " + sid);
oDiv.style.display = oDiv.style.display == " none " ? " block " : " none " ;
target.innerHTML = oDiv.style.display == " none " ? " 显示 " : " 隐藏 " ;
}
// ]]>
</ script >
在GridView调用的代码如下:
< ItemTemplate >
< div style = " font-weight: bold; background-color: #DEDEDE; " >
< span style = " float: right;
color: Red; cursor: pointer " οnclick= " ShowHidden( ' <%#Eval("Order_Id") %> ' , event ) " >显示</span></div>
< div style = " display: none; " id = " div<%#Eval( " Order_Id " ) %> " >
< table >
< tr >
< td >
备注: </ td >
< td colspan = " 2 " >
< asp:TextBox ID = " txtordertext " runat = " server " Height = " 47px " TextMode = " MultiLine " Text = ' <%#Eval("Order_Text") %> ' Width = " 122px " ></ asp:TextBox ></ td >
</ tr >
< tr >
< td >
</ td >
< td colspan = " 2 " >
< asp:Button ID = " btsend " runat = " server " Text = " 发货 " OnClick = " Button1_Click " /></ td >
</ tr >
</ table >
</ div >
</ ItemTemplate >
有的人则可能有点迷惑,我在GridView中添加一个Button,可是我双击这个Button进入到此Button的ONClick事件中,我们怎么才能得到我们所点击的那一行的的Id(也就是我们数据库的主建)值呢?
我们经常在GirdView的Bound事件中以GridView1.Cell[ 0 ].Text得到此行的主建值,那我们怎么才能在GridView事件之外得到该行的Id值呢
说来说去,GridView也只不过是用Table的原理,所以当我们知道这些,我们就能在TableCell中下手
下面是Button的OnClick事件的代码
Button btsend = sender as Button;
TableCell tc = (TableCell)btsend.Parent;
GridViewRow gvr = (GridViewRow)tc.Parent;
eWebShop.BLL.Order bllOrder = new eWebShop.BLL.Order();
bllOrder.UpdateOrderTextAndSendTime(gvr.Cells[ 0 ].Text, ((TextBox)gvr.FindControl( " txtordertext " )).Text, DateTime.Now);
Response.Redirect(Request.Url.ToString());
到这里就不用我多说了吧!
有什么不对的地方,还请各位指点!
注:上面的展开层的js代码是用孟宪会老师的! ^ _ ^
所用到的JavaScript如下:
< script type = " text/javascript " >
// <![CDATA[
function ShowHidden(sid,ev)
{
ev = ev || window. event ;
var target = ev.target || ev.srcElement;
var oDiv = document.getElementById( " div " + sid);
oDiv.style.display = oDiv.style.display == " none " ? " block " : " none " ;
target.innerHTML = oDiv.style.display == " none " ? " 显示 " : " 隐藏 " ;
}
// ]]>
</ script >
在GridView调用的代码如下:
< ItemTemplate >
< div style = " font-weight: bold; background-color: #DEDEDE; " >
< span style = " float: right;
color: Red; cursor: pointer " οnclick= " ShowHidden( ' <%#Eval("Order_Id") %> ' , event ) " >显示</span></div>
< div style = " display: none; " id = " div<%#Eval( " Order_Id " ) %> " >
< table >
< tr >
< td >
备注: </ td >
< td colspan = " 2 " >
< asp:TextBox ID = " txtordertext " runat = " server " Height = " 47px " TextMode = " MultiLine " Text = ' <%#Eval("Order_Text") %> ' Width = " 122px " ></ asp:TextBox ></ td >
</ tr >
< tr >
< td >
</ td >
< td colspan = " 2 " >
< asp:Button ID = " btsend " runat = " server " Text = " 发货 " OnClick = " Button1_Click " /></ td >
</ tr >
</ table >
</ div >
</ ItemTemplate >
有的人则可能有点迷惑,我在GridView中添加一个Button,可是我双击这个Button进入到此Button的ONClick事件中,我们怎么才能得到我们所点击的那一行的的Id(也就是我们数据库的主建)值呢?
我们经常在GirdView的Bound事件中以GridView1.Cell[ 0 ].Text得到此行的主建值,那我们怎么才能在GridView事件之外得到该行的Id值呢
说来说去,GridView也只不过是用Table的原理,所以当我们知道这些,我们就能在TableCell中下手
下面是Button的OnClick事件的代码
Button btsend = sender as Button;
TableCell tc = (TableCell)btsend.Parent;
GridViewRow gvr = (GridViewRow)tc.Parent;
eWebShop.BLL.Order bllOrder = new eWebShop.BLL.Order();
bllOrder.UpdateOrderTextAndSendTime(gvr.Cells[ 0 ].Text, ((TextBox)gvr.FindControl( " txtordertext " )).Text, DateTime.Now);
Response.Redirect(Request.Url.ToString());
到这里就不用我多说了吧!
有什么不对的地方,还请各位指点!
注:上面的展开层的js代码是用孟宪会老师的! ^ _ ^