gpt4 book ai didi

asp.net - GridView 编辑按钮需要单击 2 次

转载 作者:行者123 更新时间:2023-12-02 18:59:00 26 4
gpt4 key购买 nike

当在gridview中按下编辑按钮时,只有点击2次后才会显示编辑模板。还有一个问题:要编辑的字段的值最初显示在 gridview 中,但不显示在编辑模板中。

ASP代码:

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" 
AutoGenerateColumns="False" CellPadding="4" OnRowEditing="EditRow"
OnRowCancelingEdit="CancelEditRow" DataKeyNames="AREA" DataMember="DefaultView">

<Columns>
<asp:BoundField DataField="AREA" HeaderText="AREA" ReadOnly="True"
SortExpression="AREA" />

<asp:TemplateField HeaderText="LEADER_USER" SortExpression="LEADER_USER">
<ItemTemplate><%#Eval("leader_user")%></ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtleaderuser" runat="server" Text='<%#Eval("leader_user")%>'/>
</EditItemTemplate>
</asp:TemplateField>

<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="editButton" runat="server" CommandName="Edit"
ImageUrl="images/pencil1.png" Text="Edit" ToolTip="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="BtnUpdate" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="BtnCancel" runat="server" CommandName="Cancel"
Text="Cancel" />
</EditItemTemplate>
</asp:TemplateField>

</Columns>
</asp:GridView>

VB代码:

Protected Sub EditRow(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
GridView1.DataSource = SqlDataSource1
'If Not IsPostBack Then
'GridView1.DataSourceID = SqlDataSource1.ID
'GridView1.DataBind()
'End If
End Sub

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

SqlDataSource1.SelectCommand = "SQL"
SqlDataSource1.ConnectionString = "My conn string"

If Not IsPostBack Then
'GridView1.DataSourceID = SqlDataSource1.ID
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End If


End Sub

最佳答案

我认为您需要调用DataBind来重新绑定(bind)数据源。您已将其注释掉,但看起来您将其放在 IsPostBack block 中,该 block 仅在初始页面加载时执行。

尝试:

Protected Sub EditRow(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
GridView1.EditIndex = e.NewEditIndex
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End Sub

关于asp.net - GridView 编辑按钮需要单击 2 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18724395/

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