gpt4 book ai didi

asp.net - 单击 LinkBut​​ton 时防止 GridView 调整大小

转载 作者:行者123 更新时间:2023-11-28 12:28:31 25 4
gpt4 key购买 nike

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

任何帮助将不胜感激

提前谢谢你

最佳答案

将 Size 设置为您的 linkbutton 以避免 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")

关于asp.net - 单击 LinkBut​​ton 时防止 GridView 调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18397345/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com