编辑项目模板调用时禁用项目模板按钮 [英] Disable Item Template Button when Edit Item Template Call

查看:52
本文介绍了编辑项目模板调用时禁用项目模板按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目模板的gridview中有删除和编辑按钮.在编辑项目模板"中,我有更新"和取消"按钮.

我想在单击编辑按钮时禁用删除"按钮.
意味着我想在编辑项目模板调用时禁用项目模板控制按钮???

怎么可能???
我还有另一种方法..但是我只需要这样做??
所以谢谢Advance
解决查询?
具有网格视图模板字段的ASP .NET(ADo .NET).

问候
库玛亲王
Software Developer

I have delete and edit buttons in gridview in item template. and In Edit Item Template i have Update and Cancel Button.

I want to disable Delete button when i click on edit button.
Means i want to disable item template control button when edit item template call???

How it is possible????
i have another way ..but my requirement to do only this way??
so Thank you Advance
Solve the Query???
ASP .NET (ADo .NET) With Grid View Templates fields.

Regards
Prince Kumar
Software Developer

推荐答案


可以实现如下:

Aspx中的网格将如下所示:

Hi,
This Can Be Attained As Follows :

The Grid in Aspx Will Be Something Like This :

<asp:GridView ID="gvwDemo" runat="server" Width="100%" AutoGenerateColumns="False"

    OnRowDataBound="gvwDemo_RowDataBound">
    <Columns>
        <asp:TemplateField HeaderText="**">
            <ItemTemplate>
                <asp:ImageButton ID="imgSave" runat="server" Visible="false" ImageUrl="~/Images/save.gif"

                    CommandName="Save" ToolTip="Save" CommandArgument='<%# Bind("PrimaryKeyID")%>'>
                </asp:ImageButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="**">
            <ItemTemplate>
                <asp:ImageButton ID="imgEdit" runat="server" ImageUrl="~/Images/edit.gif" CommandName="Edit"

                    ToolTip="Edit" CommandArgument='<%# Bind("GMDocGroupID")%>'></asp:ImageButton>
                <asp:ImageButton ID="imgCancel" Visible="false" runat="server" ImageUrl="~/Images/cancel.gif"

                    CommandName="Cancel" ToolTip="Cancel" CommandArgument='<%# Bind("PrimaryKeyID")%>'>
                </asp:ImageButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="**">
            <ItemTemplate>
                <asp:ImageButton ID="imgDelete" runat="server" ImageUrl="~/Images/delete.gif" CommandName="Delete"

                    ToolTip="Delete" CommandArgument='<%# Eval("PrimaryKeyID")%>' OnClientClick="return confirm('Are you sure that you want to delete this record?');">
                </asp:ImageButton>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="">
            <ItemTemplate>
                Your Controls Here
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>





在Cs文件中编写此代码:


public void gvwDemo_RowDataBound(object sender,GridViewRowEventArgs e)
{

如果(e.Row.RowType == DataControlRowType.DataRow&& gvwDemo.EditIndex == 0)
{
ImageButton imgSave =(ImageButton)e.Row.FindControl("imgSave");
如果(imgSave!= null)
{
imgSave.Visible = true;
gvwDemo.Columns [0] .Visible = true;
}
ImageButton imgDelete =(ImageButton)e.Row.FindControl("imgDelete");
如果(imgDelete!= null)
{
imgDelete.Visible = true;
gvwDemo.Columns [2] .Visible = true;
}

}
其他
{
ImageButton imgEdit =(ImageButton)e.Row.FindControl("imgEdit");
如果(imgEdit!= null)
{
imgEdit.Visible = true;
}
ImageButton imgDelete =(ImageButton)e.Row.FindControl("imgDelete");
如果(imgDelete!= null)
{
imgDelete.Visible = true;
gvwDemo.Columns [2] .Visible = true;
}
ImageButton imgSave =(ImageButton)e.Row.FindControl("imgSave");
如果(imgSave!= null)
{
imgSave.Visible = false;
gvwDemo.Columns [0] .Visible = false;
}
}
if(e.Row.RowType == DataControlRowType.DataRow&& gvwDemo.EditIndex> = 0)
{
ImageButton imgEdit =(ImageButton)e.Row.FindControl("imgEdit");
imgEdit.Visible = false;

ImageButton imgCancel =(ImageButton)e.Row.FindControl("imgCancel");
imgCancel.Visible = true;

ImageButton imgSave =(ImageButton)e.Row.FindControl("imgSave");
如果(imgEdit!= null)
{
imgSave.Visible = true;
gvwDemo.Columns [0] .Visible = true;
}

ImageButton imgDelete =(ImageButton)e.Row.FindControl("imgDelete");
如果(imgDelete!= null)
{
imgDelete.Visible = false;
gvwDemo.Columns [2] .Visible = false;
}
}
}





Write This Code in Cs File:


public void gvwDemo_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (e.Row.RowType == DataControlRowType.DataRow && gvwDemo.EditIndex == 0)
{
ImageButton imgSave = (ImageButton)e.Row.FindControl("imgSave");
if (imgSave != null)
{
imgSave.Visible = true;
gvwDemo.Columns[0].Visible = true;
}
ImageButton imgDelete = (ImageButton)e.Row.FindControl("imgDelete");
if (imgDelete != null)
{
imgDelete.Visible = true;
gvwDemo.Columns[2].Visible = true;
}

}
else
{
ImageButton imgEdit = (ImageButton)e.Row.FindControl("imgEdit");
if (imgEdit != null)
{
imgEdit.Visible = true;
}
ImageButton imgDelete = (ImageButton)e.Row.FindControl("imgDelete");
if (imgDelete != null)
{
imgDelete.Visible = true;
gvwDemo.Columns[2].Visible = true;
}
ImageButton imgSave = (ImageButton)e.Row.FindControl("imgSave");
if (imgSave != null)
{
imgSave.Visible = false;
gvwDemo.Columns[0].Visible = false;
}
}
if (e.Row.RowType == DataControlRowType.DataRow && gvwDemo.EditIndex >= 0)
{
ImageButton imgEdit = (ImageButton)e.Row.FindControl("imgEdit");
imgEdit.Visible = false;

ImageButton imgCancel = (ImageButton)e.Row.FindControl("imgCancel");
imgCancel.Visible = true;

ImageButton imgSave = (ImageButton)e.Row.FindControl("imgSave");
if (imgEdit != null)
{
imgSave.Visible = true;
gvwDemo.Columns[0].Visible = true;
}

ImageButton imgDelete = (ImageButton)e.Row.FindControl("imgDelete");
if (imgDelete != null)
{
imgDelete.Visible = false;
gvwDemo.Columns[2].Visible = false;
}
}
}


这篇关于编辑项目模板调用时禁用项目模板按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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