We help IT Professionals succeed at work.

Gridview button focus

DTwined
DTwined asked
on
I have a Gridview that has a Delete button on each row. The first button is always highlighted/selected by default. Is there a way I can set it so none of the Delete buttons are ever selected/highlighted by default?

ASP.NET 3.5

thanks!

<asp:GridView ID="gridview1"
            runat="server"
            Width="600px"
            ShowFooter="True"
            RowStyle-VerticalAlign="Middle"
            RowStyle-HorizontalAlign="Center"
            onselectedindexchanged="gridview1_SelectedIndexChanged"
            AutoGenerateColumns="false"
            DataKeyNames="Serial"
            OnRowDeleted="gridview1_RowDeleted"
            OnRowDeleting="gridview1_RowDeleting"
            OnRowCommand="gridview1_RowCommand"
            OnRowDataBound="gridview1_RowDataBound" TabIndex="8">
           
            <RowStyle HorizontalAlign="Center" VerticalAlign="Middle" />
           
            <EmptyDataRowStyle
                BorderColor="Black"
                BorderStyle="Solid"
                BorderWidth="1px"
                Height="100px"
                HorizontalAlign="Left"
                Width="200px" />
           
            <Columns>
                <asp:boundfield datafield="Serial" HeaderText="Serial"  htmlencode="false" />
                <asp:boundfield datafield="PartNumber" HeaderText="Part Number" htmlencode="false" />
                <asp:boundfield datafield="ProductName" HeaderText="Product Name"  htmlencode="false" />
           
            <asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:Button ID="btnDelete"
                                runat="server"
                                Text="Delete" TabIndex="0"
                                CommandArgument='<%# Eval("ID") %>'
                                CommandName="Delete" />
                </ItemTemplate>
            </asp:TemplateField>
           
            </Columns>
            </asp:GridView>
Comment
Watch Question

Can you try UseSubmitBehavior="True" in your code? like below.
<asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:Button ID="btnDelete"
                                runat="server"
                                UseSubmitBehavior="True"
                                Text="Delete" TabIndex="0"
                                CommandArgument='<%# Eval("ID") %>'
                                CommandName="Delete" />
                </ItemTemplate>
            </asp:TemplateField>

Open in new window

sorry I mean UseSubmitBehavior="False"
<asp:TemplateField HeaderText="Delete">
                <ItemTemplate>
                    <asp:Button ID="btnDelete"
                                runat="server"
                                UseSubmitBehavior="False"
                                Text="Delete" TabIndex="0"
                                CommandArgument='<%# Eval("ID") %>'
                                CommandName="Delete" />
                </ItemTemplate>
            </asp:TemplateField>

Open in new window