2017-07-28 17 views
0

リストビューを使用しているaspxページがあります。私が持っている削除ボタンは、リストビューで見つかったIDを使用してSQLの削除を実行する必要があります。ListView ItemCommandがボタンクリックで届かない

ASPX:背後に

<asp:ListView runat="server" ID="ListView2" OnItemDataBound="ListView2_ItemDataBound" OnItemCommand="ListView2_ItemCommand"> 
       <LayoutTemplate> 
        ... 
        <asp:DataPager runat="server" ID="DataPager" PageSize="10" OnPreRender="DataPager_PreRender"> 
         <Fields> 
          ... 
         </Fields> 
        </asp:DataPager> 
       </LayoutTemplate> 
       <ItemTemplate> 
        ... 
         <td runat="server" align="right" colspan="4"><asp:Button ID="deleteRButton" CssClass="Button" runat="server" Text="Delete" CommandName="deleteRButton" OnClientClick="return confirm('You are about to delete this forum response. Are you sure you want to proceed?');" /></td> 
        ... 
       </ItemTemplate> 
     <ItemSeparatorTemplate> 
     </ItemSeparatorTemplate> 
</asp:ListView> 

コード:

protected void ListView2_ItemCommand(object sender, ListViewCommandEventArgs e) 
    { 
      if (e.CommandName == "deleteRButton") //Never makes it here with breakpoints 
     { 
      ... 
      //Find label value and execute SQL 
     } 

    } 

どのように私はボタンを項目コマンドコードを実行するためにクリックするのですか?私はOnClickメソッド(火災)も使用しようとしましたが、ラベルID値へのアクセスはありません。

EDIT:

共有ページのロードイベント:

protected void Page_Load(object sender, EventArgs e) 
    { 
     GetQuestions(); //builds data table and binds to listview 1 
     GetAnswers(); //builds data table and binds to listview 2 
     questionIDBreadCrumb.Text = grabID(); //grabs id from url 
     //loads the current userID 
     getUserData(); 
    } 
+0

可能であれば、あなたの 'Page_Load'イベントを共有してください。 – Prabhat

+0

@Prabhat編集の参照 –

+0

'If(!IsPostback){...}'の中に 'getUserData();'をラップしてもう一度実行します。 '!IsPostback'の中にすべてのコンテンツをラップする方が良いでしょう。 – Prabhat

答えて

0

SOLUTION:(!IsPostBackプロパティ)であれば内部で

は、ページロードイベントを置く問題を解決しました。

if (!IsPostBack) 
     { 
      GetQuestions(); 
      GetAnswers(); 
      questionIDBreadCrumb.Text = grabID(); 

      //loads the current userID 
      getUserData(); 
      //validates questionOwner 
     } 
関連する問題