单击LinkBut​​ton时阻止GridView调整大小

时间:2013-08-23 07:36:35

标签: asp.net css vb.net

如何在点击编辑链接按钮时阻止我的网格调整大小?我只需要修复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

任何帮助将不胜感激

提前谢谢

1 个答案:

答案 0 :(得分:0)

将大小设置为您的链接按钮以避免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")