当前位置: 首页 > news >正文

网站注册食品网站的网页设计

网站注册,食品网站的网页设计,织梦网站挂马教程,快速html5网页设计的网站在.net2.0中&#xff0c;实现对gridview删除行时弹出确认对话框的四种方法 1&#xff0c;GridView中如何使用CommandField删除时&#xff0c;弹出确认框? 在VS2005提供的GridView中我们可以直接添加一个CommandField删除列&#xff1a;<asp:CommandField ShowDeleteButton&…

    在.net2.0中,实现对gridview删除行时弹出确认对话框的四种方法 1,GridView中如何使用CommandField删除时,弹出确认框? 
在VS2005提供的GridView中我们可以直接添加一个CommandField删除列:<asp:CommandField ShowDeleteButton="True" />,完后在它的RowDeleting事件中完成删除。但在多半我们在做这种删除操作时都需要先让操作者再确认下,完后再进行删除,以避免误操作引起的误删除。
可以通过下面方法给GridView删除前加上个确认对话框。
首先,在GridView的属性对框话框中点击“Columns”进入它的“字段”设计器。接着在“字段”设计器中选择以前已加上的那个CommandField“删除”列,这时在它的属性列表下会看到一个“将此它段转换为 TemplateFied”的项,点击将它转换为TemplateFied列。
完后退出该字段设计器,切换到源码视图你会发现该列已由原来的:<asp:CommandField ShowDeleteButton="True" />
变为了:
CODE:
<asp:TemplateField ShowHeader=&amp;quot;False&amp;quot;>
    <ItemTemplate>
     <asp:LinkButton ID=&amp;quot;LinkButton1&amp;quot; runat=&amp;quot;server&amp;quot; CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;Delete&amp;quot;    Text=&amp;quot;删除&amp;quot;></asp:LinkButton>
</ItemTemplate>
最后在<asp:LinkButton>中加入:

OnClientClick="javascript:return confirm('真的要删除吗?');"

或者加入:

OnClientClick="if(confirm('你确定要删除此记录吗?')){return true;}else{return false;}"

这样点击删除时就会先在客户端弹出“确认要删除吗?”对话框,而原来在RowDeleting事件中写的代码完全不用改变。

注意:CommandName="delete" CommandName 一定要设为"delete",否则将不触发GridView中的RowDeleting 事件.

注意:在事件protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)里需要设置GridView中的DataKeysName = Fid,才可以找到相应的ID.Fid为表的主键 id

 

2,

CODE:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowIndex > -1)
        {
            int id = Convert.ToInt32(GridView1.DataKeys[e.Row.RowIndex].Value);
            LinkButton lbtnDelete = (LinkButton)e.Row.FindControl(&amp;quot;lbtnDelete&amp;quot;);
        if (lbtnDelete != null)
        {
            lbtnDelete.CommandArgument = id.ToString();
            lbtnDelete.Attributes.Add(&amp;quot;onClick&amp;quot;, &amp;quot;<script>return confirm(’是否确认删除!’)</script>&amp;quot;);
        }
    }
}
3,针对C#中的Windows窗体程序,可以先引用System.windwos.Forms,然后在进行处理;对于Web应用程序不适合。

CODE:
using System.Windows.Forms;

protected void gvNewList_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    DialogResult result = MessageBox.Show(&amp;quot;确定要删除本行吗?&amp;quot;, &amp;quot;信息提示!&amp;quot;, MessageBoxButtons.YesNo, MessageBoxIcon.Question,MessageBoxDefaultButton.Button2,MessageBoxOptions.ServiceNotification);
    if (result == DialogResult.Yes)
    {
        e.Cancel = false;
    }
    else
    {
        e.Cancel = true;
    }
}
4,添加一个删除列

CODE:
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
    TableCell tc = (TableCell)e.Row.Cells[e.Row.Cells.Count - 1];
    for (int i = 0; i < tc.Controls.Count; i += 2)
    {
        // cerco il controllo ImageButton (ho utilizzato quello)
        Object o = tc.Controls[i];
        if (o is ImageButton)
        {
            // controllo trovato!
            // ora aggiungo l’evento js onClick per chiedere conferma all’utente
            ImageButton lb = (ImageButton) o;
            ((ImageButton)lb).Attributes.Add(&amp;quot;onclick&amp;quot;, @&amp;quot;javascript:return confirm('Attenzione: sicuro di voler cancellare?');&amp;quot;);
        }
    }
}


-------------------------------------------------------------
CODE:
<asp:TemplateField ShowHeader=&amp;quot;False&amp;quot;>
<ItemStyle HorizontalAlign=&amp;quot;Center&amp;quot; Width=&amp;quot;16px&amp;quot; />
<ItemTemplate>
<asp:ImageButton ID=&amp;quot;imgDelete&amp;quot; runat=&amp;quot;server&amp;quot; CausesValidation=&amp;quot;False&amp;quot; CommandName=&amp;quot;Delete&amp;quot; ImageUrl=&amp;quot;~/img/ico_elimina.gif&amp;quot; AlternateText=&amp;quot;Cancella data&amp;quot; OnClientClick=&amp;quot;return confirm(’Sicuro di voler cancellare?’);&amp;quot; />
</ItemTemplate>
</asp:TemplateField>


以上方法总结
---------Template 方式 -----------------------------------------------
CODE:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<aspinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandName="Delete"
Text="删除" OnClientClick=’return confirm("Are you sure you want to delete this record?");’></aspinkButton>
</ItemTemplate>
</asp:TemplateField>


-------------RowDeleting method------------------------------------------------

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{

    Response.Write("<script language=javascript>window.confirm('确定删除吗?')</script>");
}

-------------RowDataBound method--------------------------------------------------------------
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        ((LinkButton)e.Row.Cells[4].Controls[0]).Attributes.Add("onclick", "javascript:return confirm(’确实要删除该记录吗?’)");
    }

}

 

另外:在web页面中,在按钮事件中添加弹出对话框的方法还有,

在前台点击按钮如b1,事件为b1_click,在后台写b1_click的代码,实现点击后弹出:“确定要删除吗?”选择确定,跳转页面如:aa.aspx,选择取消,无动作!

protected void Page_Load(object sender, EventArgs e)
{
    b1.Attributes.Add("onclick", "javascript:if(confirm('确定要删除吗?')){}else{return false;}");
}
此方法简单方便,屡试不爽

http://www.yayakq.cn/news/478363/

相关文章:

  • 宜昌住房和城乡建设厅网站网站 站外链接
  • 创建网站超市ps软件下载手机版
  • 服务器不稳定 如何让百度重新收录网站公司设计网站需要包含什么资料
  • 东营网站建设制作深圳福步外贸论坛
  • 建网站什么赚钱网站开发的职业决策
  • 郑州做网站哪家好微信小程序一年费用多少钱
  • 响应式网站对seo网络平台怎么做
  • 昆山企业网站设计asp 手机网站
  • 揭阳网站制作机构织梦中英文网站源码
  • 网站建设服务器的选择方式包括哪些做网站排名优化是怎么回事
  • 在centos做网站南郑县城乡建设局网站
  • 岳阳建设厅网站网络营销做女鞋的网站设计
  • 网站建设步骤图vip域名做网站好不好
  • 做网站 南京淮海中路街道网站建设
  • 展会网站建设装修设计图免费
  • 网站后台更新无法在网页显示互联网网站开发发展
  • 合肥网站建设 卫来网络推广运营策略
  • 国内产品设计网站微信公众号第三方管理平台
  • 500亿网站建设酒店网站建设设计
  • 专业的深圳网站建设公司排名悦阁网站开发旗舰店
  • 网站建站流程有哪些中国菲律宾世预赛
  • 湖北营销网站建设设计手机兼职赚钱正规平台
  • 简约式网站模板某网站突然不能浏览了
  • 为什么用wp做网站重庆搜狗推广
  • 先做它个天猫网站wordpress cms 插件
  • 寻找做电影网站团队合作做体育设施工程公司的网站
  • 东台网站制作公司seo整站优化哪家专业
  • 马云做黄页网站时候做图表网站
  • 可信网站申请网站建设制作优化
  • 南昌网站建设公司案例辽宁省建设部网站