开发者

CommandField: Can I prohibit Update and Cancel when Edit clicked

i am using vs2010, .net 4. the first column in my gridview is a CommandField which on initial rendering shows Edit Delete and Set Default as linkbuttons. when Edit clicked i have a popup with a form which when accepted updates my database. my problem is开发者_如何学C that CommandField shows Update and Cancel which i dont want.

is there a way to prevent the Update and Cancel when Edit is clicked.

thanks in advance for any help.

this is my partial gridview:

<asp:GridView runat="server" ID="lstComponents" Width="100%" BorderWidth="1px" BorderStyle="None"
EnableViewState="True" AutoGenerateColumns="False"  DataKeyNames="ComponentID,ComponentName,ComponentType,IPAddress" 
CellPadding="0" CellSpacing="0" OnRowDataBound="lstComponents_RowDataBound" AllowSorting="false"
HeaderStyle-CssClass="ListHeader" HeaderStyle-ForeColor="White" OnSelectedIndexChanging="lstComponents_SelectedIndexChanging"
OnRowEditing="lstComponents_RowEditing" OnRowDeleting="lstComponents_RowDeleting" >
<Columns>
 <asp:CommandField  ShowDeleteButton="true" ShowSelectButton="true" ShowEditButton="True"
 HeaderStyle-CssClass="ListHeader" SelectText="Set Default" ItemStyle-CssClass="ListData"
HeaderStyle-Width="150px">
<HeaderStyle CssClass="ListHeader" Width="150px" />
<ItemStyle CssClass="ListData" />
</asp:CommandField>


Remove ShowEditButton="True" from your asp:CommandField and add a linkButton additionally within an ItemTemplate and perform your logic in the linkButton's OnClick event/OnClientClick event .

see the updated code,

           <asp:GridView runat="server AutoGenerateColumns="False"   DataKeyNames="ComponentID,ComponentName,ComponentType,IPAddress" 
                            CellPadding="0" CellSpacing="0" OnRowDataBound="lstComponents_RowDataBound" 
                            HeaderStyle-CssClass="ListHeader" HeaderStyle-ForeColor="White" OnSelectedIndexChanging="lstComponents_SelectedIndexChanging"
                            OnRowEditing="lstComponents_RowEditing" OnRowDeleting="lstComponents_RowDeleting" >
                            <Columns>

        <asp:TemplateField>
               <ItemTemplate>                                       
                   <asp:LinkButton ID="LinkButton1" OnClick="LinkButton1_Click" runat="server" Text="edit">LinkButton</asp:LinkButton>
                </ItemTemplate>
        </asp:TemplateField>

        <asp:CommandField  ShowDeleteButton="true" ShowSelectButton="true"
                                    HeaderStyle-CssClass="ListHeader" SelectText="Set Default" ItemStyle-CssClass="ListData"
                                    HeaderStyle-Width="150px">
                                    <HeaderStyle CssClass="ListHeader" Width="150px" />
                                    <ItemStyle CssClass="ListData" />
                                </asp:CommandField>

Hope this helps you...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜