0

单击编辑链接按钮时,如何防止我的网格调整大小?我只需要修复我的gridview..

请注意,当您单击编辑链接按钮时,会出现 2 个按钮:1 个用于更新,1 个用于取消,而在其他单元格中,文本框似乎会更新值,这就是我的网格正在调整大小的原因.. 我该如何解决这个问题?

这是我的asp代码:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" onrowdatabound="GridView1_RowDataBound" 
        AutoGenerateColumns="False" Width="604px" 
        DataKeyNames="id,firstname,lastname,adress,email,telephone,birthday">

        <Columns>
        <asp:TemplateField>

                <ItemTemplate>
                      <asp:CheckBox id="Select" runat="server" OnCheckedChanged="CheckedChanged" AutoPostBack="false"/>
                      <asp:LinkButton  ID="idedit" CommandName="Edit" CausesValidation="true" runat="server"
                            ToolTip="Edit"  Text="Edit"/>
                      <asp:LinkButton ID="selectID" CommandName="Select" CausesValidation="true" runat="server"
                            ToolTip="Select"  Text="Select" />
                    </ItemTemplate>

                <EditItemTemplate>

                 <asp:LinkButton  ID="idupdate" CommandName="Update" runat="server" CausesValidation="false" Text="Update"
                            ToolTip="Update" OnClientClick="javascript:if(!confirm('Are you sure do you want to update this?')){return false;}" />
                        <asp:LinkButton  ID="idcancel" runat="server" CommandName="Cancel" CausesValidation="false"
                            Text="Cancel" ToolTip="Cancel"/>
                </EditItemTemplate>
                </asp:TemplateField>

            <asp:TemplateField HeaderText="firstname">
                <EditItemTemplate> 
                    <asp:TextBox ID="fnmaetxt" runat="server" Text='<%# Bind("firstname") %>'></asp:TextBox>
                    <%--<asp:RequiredFieldValidator ID="EmailRequired" runat="server" ControlToValidate="fnmaetxt" Text="The first name field is required!"/>--%>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lblfirstname" runat="server" Text='<%# Bind("firstname") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 

            <asp:TemplateField HeaderText="lastname">
                <EditItemTemplate> 
                    <asp:TextBox ID="lnametxt" runat="server" Text='<%# Bind("lastname") %>'></asp:TextBox>
                    <%--<asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="lnametxt" Text="The last name field is required!"
                                        runat="server" />--%>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lbllastname" runat="server" Text='<%# Bind("lastname") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 

            <asp:TemplateField HeaderText="adress">
                <EditItemTemplate> 
                    <asp:TextBox ID="adresstxt" runat="server" Text='<%# Bind("adress") %>'></asp:TextBox>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lbladress" runat="server" Text='<%# Bind("adress") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 

            <asp:TemplateField HeaderText="email">
                <EditItemTemplate> 
                    <asp:TextBox ID="emtailtxt" runat="server" Text='<%# Bind("email") %>'></asp:TextBox>
                    <%--<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="emtailtxt" Text="Not a Valid Email Address" SetFocusOnError="True" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" />--%>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lblemail" runat="server" Text='<%# Bind("email") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 


           <asp:TemplateField HeaderText="telephone">
                <EditItemTemplate> 
                    <asp:TextBox ID="phonetxt" runat="server" Text='<%# Bind("telephone") %>'></asp:TextBox>
                    <%--<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ControlToValidate="phonetxt" Text="Not a Valid phone number " SetFocusOnError="True" ValidationExpression="\d{8}"/>--%>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lbltelephone" runat="server" Text='<%# Bind("telephone") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 


           <asp:TemplateField HeaderText="birthday">
                <EditItemTemplate> 
                    <asp:TextBox ID="birthdaytxt" runat="server" Text='<%# Bind("birthday") %>'></asp:TextBox>
                </EditItemTemplate> 
                <ItemTemplate> 
                    <asp:Label ID="lblbirthday" runat="server" Text='<%# Bind("birthday") %>'></asp:Label> 
                </ItemTemplate> 
            </asp:TemplateField> 

        </Columns>

    </asp:GridView>

这是我在编辑事件中的代码:

Protected Sub GridView1_RowEditing(sender As Object, e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing
    GridView1.EditIndex = e.NewEditIndex
    GridView1.DataSource = x.selectProfile
    GridView1.DataBind()
End Sub

任何帮助将非常感激

先感谢您

4

1 回答 1

0

将 Size 设置为您的链接按钮以避免 gridview 调整大小

<asp:LinkButton  ID="idcancel" runat="server" CommandName="Cancel" CausesValidation="false"  Text="Cancel" ToolTip="Cancel" width="100px" />

或者

试试这个代码 page_load 设置你的gridview

gridview.Attributes.Add("style", "word-break:break-all; word-wrap:break-word")
于 2013-08-23T08:37:51.587 回答