2017-02-08 20 views
0

私はbuttonを持っています。これはDatalistの上にあります。ユーザーが検索を行うたびに、返されたレコードはDatalistにバインドされます。ボタンのASP.NET VBはデータリストを編集モードに設定します

コード: データリストのための<asp:Button ID="Button1" runat="server" Text="Edit" CommandName="edit"/>

コード:.vbファイルで

<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> 

、私が持っている:

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。私はそれを間違ってやっていますか?あるいは、そのような方法を実装することさえ可能ですか?

答えて

0

ボタンはDatalistの外にあるので、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 

ただし、一度に1つのアイテムしかeditに設定することはできません。

+0

あなたのアドバイスありがとうございました! –

関連する問題