【问题标题】:ASP.NET VB Set Datalist to edit modeASP.NET VB 将 Datalist 设置为编辑模式
【发布时间】:2017-02-09 03:03:40
【问题描述】:

我有一个button,它位于Datalist 之上。用户每次搜索,返回的记录都会绑定到Datalist

按钮代码: <asp:Button ID="Button1" runat="server" Text="Edit" CommandName="edit"/>

数据列表代码:

<asp:DataList ID="UserMatrixDataList" runat="server" RepeatColumns="1" CellSpacing="6" RepeatLayout="Table" BorderWidth="5">
    <ItemTemplate>
        <table class="table">
            <col width="130">
            <col width="800">
            <tr>
                <td>
                    <strong>Level</strong>
                </td>
                <td>
                    <asp:Label ID="lblLevel" runat="server" Text='<%# Eval("Level")%>'></asp:Label>
                </td>
            </tr>
        </table>
    </ItemTemplate>
    <EditItemTemplate>
        <table class="table">
            col width="130">
                <col width="800">
            <tr>
                <td>
                    <strong>Level</strong>
                </td>
                <td>
                    <asp:TextBox ID="txtLevel" runat="server" Text='<%# Eval("Level")%>'></asp:TextBox>
                </td>
            </tr>
        </table>
    </EditItemTemplate>
</asp:DataList>

在 .vb 文件中,我有:

Protected Sub UserMatrixDataList_EditCommand(source As Object, e As DataListCommandEventArgs)

    For i = 0 To UserMatrixDataList.Items.Count

        UserMatrixDataList.EditItemIndex = e.Item.ItemIndex
        UserMatrixDataList.DataBind()

    Next
End Sub

但是,单击button 后没有任何反应。知道我在哪里做错了吗?或者甚至可以实现这样的方法?

【问题讨论】:

    标签: asp.net vb.net datalist


    【解决方案1】:

    由于按钮在数据列表之外,它不会使用EditCommand 方法。但是您仍然可以使用该按钮设置 EditIndex。

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        'if you need this line depends on how and where you are binding the data to the datalist
        UserMatrixDataList.DataSource = source
    
        UserMatrixDataList.EditIndex = 6
        UserMatrixDataList.DataBind
    End Sub
    

    但您一次只能将一项设置为edit

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-19
      • 2023-03-17
      • 2011-05-21
      • 1970-01-01
      • 2015-06-20
      • 2012-02-05
      相关资源
      最近更新 更多