GridView删除确认MSG错误 [英] GridView Delete Confirm MSG Error

查看:65
本文介绍了GridView删除确认MSG错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI!



我有一个带有两个命令字段的Gridview(删除,编辑)。如果用户点击删除,我想获得确认消息,它工作正常,但如果他点击更新,我会收到错误消息。



代码是:

  if (e.Row.RowType == DataControlRowType.DataRow)
{
// 引用Delete LinkBut​​ton
LinkBut​​ton db =(LinkBut​​ton)e.Row .Cells [ 5 ]。控制[ 0 ];
db.OnClientClick = return confirm('Biztos benne,hogytörölnikívánjaakiválasztottcélt?'); ;
}





和gridview是:



< pre lang =xml> < asp:GridView ID = GridView1 runat = server AlternatingRowStyle-CssClass = gridview_alter

AutoGenerateColumns = False EmptyDataText = GridLines = OnRowCancelingEdit = RowCancelingEdit

< span class =code-attribute>
OnRowDataBound = GridView1_RowDataBound OnRowDeleting = RowDeleting OnRowEditing = RowEditing

OnRowUpdating = RowUpdating ShowHeaderWhenEmpty = True 宽度 = 820px >
< AlternatingRowStyle CssClass = gridview_alter / >
< >
< asp:TemplateField HeaderText < span class =code-keyword> =
Leírás 可见 = false / >
< asp:BoundField DataField = 描述 HeaderStyle-Width = 150 HeaderText = Leírás HtmlEncode = false >
< HeaderStyle 宽度 = 150px / >
< / asp:BoundField >
< asp:BoundField HeaderText = Kritérium DataField = IndexNumber / >
< asp:BoundField DataField = 重量 HeaderStyle-Width = 50 HeaderText = Súly >
< HeaderStyle 宽度 = 50px / >
< / asp:BoundField >
< asp:TemplateField HeaderStyle-Width = 100 HeaderText = Céltípusa >
< ItemTemplate >
< asp:标签 ID = lblGoalType runat = 服务器 > < / asp:标签 >
< / ItemTemplate >
< HeaderStyle 宽度 =< /跨度> < span class =code-keyword> 100px / >
< / asp:TemplateField >
< asp:CommandField DeleteText = Törlés HeaderStyle-Width = 60 ShowDeleteButton = true >
< HeaderStyle 宽度 = 60px / >
< / asp:CommandField >
< asp:CommandField CancelText = Mégse DeleteText = Törlés EditText = Szerkesztés

< span class =code-attribute> HeaderStyle-Width = 60 ShowEditButton = True UpdateText = Frissítés

ValidationGroup = Leírás,Súly >
< HeaderStyle 宽度 = 60px / >
< / asp:CommandField >
< /列 >
< / asp:GridView > < /跨度>







我在这里得到错误:

LinkBut​​ton db =(LinkBut​​ton)e.Row.Cells [5] .Controls [0];

,错误是:

指定的参数超出了有效值的范围。

解决方案

我找到了解决方案:

  foreach (DataControlFieldCell cell  in  e.Row.Cells)
{
// 检查一行中的所有单元格
foreach (控制控件 cell.Controls )
{
// 必须在此处使用LinkBut​​ton而不是ImageButton
// 如果你有链接(不是图像)作为命令按钮。
LinkBut​​ton button = control < span class =code-keyword> as LinkBut​​ton;
if (button!= null && button.CommandName == 删除
// < span class =code-comment>添加删除确认
button.OnClientClick = return确认('Biztos benne,hogytörölnikívánjaakiválasztottcélt?');;
}
}



无论如何,每个阅读它的人都希望它可以帮助任何遇到同样问题的人。


尝试

 <   asp:TemplateField     ShowHeader   =  False >  
< ItemTemplate >
< ; asp:ImageButton ID = DeleteButton runat = 服务器 ImageUrl = 〜/ image.png

CommandName = 删除 OnClientClick = 返回确认('您确定要删除吗?');

< span class =code-attribute> AlternateText = 删除 / >
< / ItemTemplate >
< / asp:TemplateField >



这是示例 [ ^ ]确认框。


HI!

I have a Gridview with two command fields(Delete, Edit). I want to get a Confirm msg if the user clicks on delete, it works fine, but if he clicks on update, i get an error msg.

The code is:

if (e.Row.RowType == DataControlRowType.DataRow)
            {
                // reference the Delete LinkButton
                LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
                db.OnClientClick = "return confirm('Biztos benne, hogy törölni kívánja a kiválasztott célt?');";
            }



and the gridview is:

<asp:GridView ID="GridView1" runat="server" AlternatingRowStyle-CssClass="gridview_alter"

                       AutoGenerateColumns="False" EmptyDataText=" " GridLines="None" OnRowCancelingEdit="RowCancelingEdit"

                       OnRowDataBound="GridView1_RowDataBound" OnRowDeleting="RowDeleting" OnRowEditing="RowEditing"

                       OnRowUpdating="RowUpdating" ShowHeaderWhenEmpty="True" Width="820px">
                       <AlternatingRowStyle CssClass="gridview_alter" />
                       <Columns>
                           <asp:TemplateField HeaderText="Leírás" Visible="false" />
                           <asp:BoundField DataField="Description" HeaderStyle-Width="150" HeaderText="Leírás" HtmlEncode="false">
                               <HeaderStyle Width="150px" />
                           </asp:BoundField>
                           <asp:BoundField HeaderText="Kritérium" DataField="IndexNumber" />
                           <asp:BoundField DataField="Weight" HeaderStyle-Width="50" HeaderText="Súly">
                               <HeaderStyle Width="50px" />
                           </asp:BoundField>
                           <asp:TemplateField HeaderStyle-Width="100" HeaderText="Cél típusa">
                               <ItemTemplate>
                                   <asp:Label ID="lblGoalType" runat="server"></asp:Label>
                               </ItemTemplate>
                               <HeaderStyle Width="100px" />
                           </asp:TemplateField>
                           <asp:CommandField DeleteText="Törlés" HeaderStyle-Width="60" ShowDeleteButton="true">
                               <HeaderStyle Width="60px" />
                           </asp:CommandField>
                                       <asp:CommandField CancelText="Mégse" DeleteText="Törlés" EditText="Szerkesztés"

                                           HeaderStyle-Width="60" ShowEditButton="True" UpdateText="Frissítés"

                                           ValidationGroup="Leírás, Súly">
                               <HeaderStyle Width="60px" />
                           </asp:CommandField>
                       </Columns>
                   </asp:GridView>




I get the error here:
LinkButton db = (LinkButton)e.Row.Cells[5].Controls[0];
and the error is:
Specified argument was out of the range of valid values.

解决方案

I found the solution:

foreach (DataControlFieldCell cell in e.Row.Cells)
{
    // check all cells in one row
    foreach (Control control in cell.Controls)
    {
        // Must use LinkButton here instead of ImageButton
        // if you are having Links (not images) as the command button.
        LinkButton button = control as LinkButton;
        if (button != null && button.CommandName == "Delete")
            // Add delete confirmation
            button.OnClientClick = "return confirm('Biztos benne, hogy törölni kívánja a kiválasztott célt?');";
    }
}


Anyway, thx everybody who read it, and hopefully, it will help anybody who has the same problem.


Try

<asp:TemplateField ShowHeader="False">
            <ItemTemplate>
                <asp:ImageButton ID="DeleteButton" runat="server" ImageUrl="~/image.png"

                    CommandName="Delete" OnClientClick="return confirm('Are you sure you want to delete?');"

                    AlternateText="Delete" />
            </ItemTemplate>
        </asp:TemplateField>


Here is an example[^] of the confirmation box.


这篇关于GridView删除确认MSG错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆