实现删除数据前弹出询问提示框主要有四中方法:

  一、在.aspx或.ascx文件中增加客户端JS脚本:

  把下面的代码直接加到.aspx或.ascx文件中即可,注意其中的“删除”二字根据自己的需要进行修改:

<script   language="JavaScript">  
function   delete_confirm(e){  
 if(event.srcElement.outerText=="删除"){
   event.returnValue=confirm("确定要删除该记录吗?");
 }  
}  
document.onclick=delete_confirm;
</script>

引用
<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemStyle ForeColor="Red" />
<ItemTemplate>
 <asp:LinkButton ID="BtnDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>然后给它加上客户端事件OnClientClick,事件执行代码为“return confirm('确认要删除此行信息吗?')”。增加后的代码如下:

引用
<asp:TemplateField HeaderText="Delete" ShowHeader="False">
<ItemStyle ForeColor="Red" />
<ItemTemplate>
 <asp:LinkButton ID="BtnDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('确认要删除此行信息吗?')"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>DataGrid与GridView在编辑状态的时候,文本框的长度过长这是人所皆知的了,下面给出两个自定长度的方法:

  一、编写事件代码:

  在ItemDataBound事件中加入以下代码即可(只适合DataGrid,GridView的方法还没想出来):(二)C#
       System.Web.UI.WebControls.TextBox txtEdit;
       Int i;
       If(e.Item.ItemType == ListItemType.EditItem)
       {
           for(i=0;i<e.Item.Cells.Count;i++)
           {
               txtEdit=e.Item.Cells[i].Controls[0];
               txtEdit.Width=System.Web.UI.WebControls.Unit.Pixel(100);
           }
       }

相关文章:

  • 2022-03-06
  • 2022-02-10
  • 2022-12-23
  • 2021-11-09
  • 2022-12-23
  • 2022-02-01
  • 2021-06-08
猜你喜欢
  • 2021-12-31
  • 2022-12-23
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-07-25
相关资源
相似解决方案