
Email feed
- Author:zhouwenqi
- Date:2008-10-26 2:46:52
今天在做一个后台的时候,我想偷下懒直接用RowCommand事件给GridView添加空行加上数据并编辑,结果发现,在每次执行RowCommand的时候要执行两次,我以为我自己搞错了,结果在网上一搜,发现有很多人有这个问题,据说是IE7还是IIS7(具体他们也没讲清楚)的问题,如果用Image作用按扭执行RowCommand就会执行两次,在IE5,IE6,FireFox下都是正常的,而且说微软也证实这个BUG!
我半信半疑的看了他们的解决方法,一种是在RowCommand事件中加上代码
if (Request["x"] == null && Request["y"] == null)
Response.End();另一种是微软的官方解决方案(我没有去证实):“尽量不在gridview里面用imagebutton,而用link或者button”(居然有这种回答),如果一定要在GridView中使用ImageButton的话,把imagebuttong加入到TemplateField中,并且在事件中调用deleterow。
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat=server id="ImageButton1" CommandName="Delete"
ImageUrl="" commandargument='<%# DataBinder.Eval(Container,
"RowIndex") %>' OnCommand="ImageButton1_Command" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>protected void ImageButton1_Command(object sender, CommandEventArgs e)
{
GridView1.DeleteRow(Int32.Parse(e.CommandArgument.ToString()));
}后面我自己试了一下,我将ImageButton换成一个Button,然后给他写了一个CSS,将图片作为他的背景就行了,至于Button的文字,不填就行了,这样的话和ImageButton没有区别了,反正这个办法我自己用的很起了,大家自己可以试一下....
.pictemplate input
{
background:url("../image/jpg/admin/textico/add.png") no-repeat center center;
border:0px;
width:20px;
height:20px;
cursor:pointer;
}- Tags:RowCommgridviewasp.net
- comments

Post your comment- Name:


- Verify code:


- Content:
-
top
Insert image
RSS
Login




