0

私はそのRepeater Control中にさまざまなボタンを持っています。

ボタンがクリックされると、それ自体を無効にして、再度クリックできないようにする必要があります。働く。

ただし、そのボタンをクリックすると、それ以外のボタンを有効にする必要があります。

そのため、クリックすると無効にする必要があります。別のボタンをクリックすると、前のボタンが有効になり、そのボタンが無効になる必要があります。

だから私は試しました:

Button btnLoad = (Button)e.Item.FindControl("btnLoad");

foreach (Button b in e.Item.Controls.OfType<Button>().Select(c => c).Where(b => b != btnLoad))
{
   b.Enabled = true;
}

btnLoad.Text = "Currently Viewing";
btnLoad.Enabled = false;

しかし、それは機能していません。配置する場所に応じて、すべてのボタンを有効のままにする (ただし、テキストを変更する) か、何もしないかのいずれかです。

これを機能させるにはどうすればよいですか?

編集:コードはここにあります:

protected void rptPdfList_ItemCommand(object source, RepeaterCommandEventArgs e)

それが私が使用する理由ですButton btnLoad = (Button)e.Item.FindControl("btnLoad");

メソッドは次の場所にあります。

switch (e.CommandName)
        {
            case "LoadDoc":
                 //Above code
               break;
        }
4

2 に答える 2

0

以下のように、ループ内で簡単な if ステートメントを試してください。

Button btnLoad = (Button)e.Item.FindControl("btnLoad");
foreach (Control c in e.Item.Controls)
    {
        if (b is Button)
        {
            if(b == btnLoad)
             {
             b.Enabled = false;
             }
            else
             {
             b.Enabled = true;
             }
        }
    }
于 2012-11-22T11:08:39.377 に答える
0

ButtonClick-event ハンドラでそのコードが必要であると仮定します。

protected void Button_Clicked(Object sender, EventArgs e)
{
    Button thisButton = (Button) sender;
    thisButton.Text = "Currently Viewing";
    RepeaterItem item = (RepeaterItem) thisButton.NamingContainer;
    IEnumerable<Button> buttons = item.Controls.OfType<Button>();
    foreach(var btn in buttons)
    {
        btn.Enabled = btn != thisButton;
    }
}
于 2012-11-22T11:09:01.150 に答える