Поле подтверждения для LinkButton в Gridview до запуска Rowcommand - PullRequest
2 голосов
/ 16 марта 2012

У меня есть gridview и linkbutton в этом виде сетки.

Когда нажимается кнопка ссылки, срабатывает rowCommand, однако я хочу попросить пользователя подтвердить щелчок в поле подтверждения,

  • если да -> rowCommand срабатывает,
  • если нет-> ничего не происходит.

Я не мог найти путь к этому.

Ответы [ 3 ]

7 голосов
/ 16 марта 2012

Добавьте это свойство OnClientClick LinkButton:

OnClientClick="return confirm('Do you really want?');"
2 голосов
/ 16 марта 2012

попробуйте это.

if (e.Row.RowType == DataControlRowType.DataRow){  
 LinkButton link = (LinkButton)e.Row.FindControl("LinkButton1");    
 link .Attributes.Add("onclick", "return confirm('Are you sure to proceed with this 
action?');");
}
0 голосов
/ 16 сентября 2016

в моем коде позади:

if (e.Row.RowType == DataControlRowType.DataRow)
{
    LinkButton del = e.Row.Cells[2].Controls[0] as LinkButton;
    del.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this role?');");
}

и в моей разметке:

<asp:GridView
    ID="GridViewRoles"
    runat="server"
    Width="350px"
    EmptyDataText="No Roles"
    AutoGenerateColumns="False"
    AllowPaging="False"
    PageSize="50"
    AllowSorting="True"
    CssClass="gridview"
    AlternatingRowStyle-CssClass="even"
    OnRowCommand="GridViewRoles_RowCommand"
    OnRowDataBound="GridViewRoles_RowDataBound"
    OnRowDeleting="GridViewRoles_RowDeleting" OnRowEditing="GridViewRoles_RowEditing">
    <Columns>

        <asp:BoundField DataField="Role" HeaderText="Role" SortExpression="Role" HeaderStyle-Width="170px" HeaderStyle-HorizontalAlign="Left" />
        <asp:ButtonField CommandName="Edit" Text="Edit" HeaderStyle-Width="50px" />
        <asp:CommandField ShowDeleteButton="True" />

    </Columns>
    <AlternatingRowStyle CssClass="even" />
</asp:GridView> 
...