Özel Komut Düğmeleri Oluşturun

Özel Komut Düğmeleri Oluşturma

Aspose.Cells.GridWeb’de özel bir komut düğmesi oluşturmak için:

  1. Web formuna Aspose.Cells.GridWeb denetimi ekleyin.
  2. Bir çalışma sayfasına erişin.
  3. CustomCommandButton sınıfının bir örneğini oluşturun.
  4. Düğmenin Komutunu bir değere ayarlayın. Bu değer, düğmenin olay işleyicisinde kullanılır.
  5. Düğmenin metnini ayarlayın.
  6. Düğmenin resim URL’sini ayarlayın.
  7. Son olarak, CustomCommandButton nesnesini GridWeb denetiminin CustomCommandButtons koleksiyonuna ekleyin.

Kod parçacığının çıktısı aşağıda gösterilmiştir:

GridWeb kontrolüne eklenen özel bir komut düğmesi

yapılacaklar:resim_alternatif_metin

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Instantiating a CustomCommandButton object
CustomCommandButton button = new CustomCommandButton();
// Setting the command, text and image URL for button. Image should be relative to website root folder
button.Command = "MyButton";
button.Text = "MyButton";
button.ImageUrl = "../Image/aspose.ico";
// Adding button to CustomCommandButtons collection of GridWeb
GridWeb1.CustomCommandButtons.Add(button);

Özel Komut Düğmesinin Olay İşleme

Özel komut düğmelerinin en önemli yönü, tıklandığında gerçekleştirdikleri eylemdir. Eylemi ayarlamak için GridWeb denetiminin CustomCommand olayı için bir olay işleyicisi oluşturun.

CustomCommand olayı, her zaman özel bir komut düğmesine tıklandığında tetiklenir. Bu nedenle, olay işleyici, düğmeyi GridWeb denetimine eklerken Komut kümesi tarafından uygulanan belirli özel komut düğmesini tanımlamalıdır. Son olarak, düğme tıklandığında yürütülen özel kodu ekleyin.

Aşağıdaki kod örneğinde butona tıklandığında A1 hücresine bir metin mesajı eklenmektedir.

Özel komut düğmesi tıklandığında A1 hücresine eklenen metin

yapılacaklar:resim_alternatif_metin

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// Creating Event Handler for CustomCommand event
protected void GridWeb1_CustomCommand(object sender, string command)
{
// Identifying a specific button by checking its command
if (command.Equals("MyButton"))
{
// Accessing the cells collection of the worksheet that is currently active
GridWorksheet sheet = GridWeb1.WorkSheets[GridWeb1.ActiveSheetIndex];
// Putting value to "A1" cell
sheet.Cells["A1"].PutValue("My Custom Command Button is Clicked.");
// Set first column width to make the text visible
sheet.Cells.SetColumnWidth(0, 30);
}
}