# InlineKeyboardMarkup, InlineKeyboardButton

**InlineKeyboardMarkup** - biroz boshqacharoq tushuncha. Uning yordami bilan biz murakkab amallarni bajarishimiz mumkin bo'ladi.

Bu turdagi klaviaturani hosil qilishda **InlineKeyboardButton** sinfiga mansub obyektlardan foydalaniladi. **InlineKeyboardButton** bir vaqtning o'zida ham tugma matnini, hamda unga biriktirilgan datani olib yuradi. Ya'ni, bu data orqali, botimizni keyingi vazifalarini belgilashimiz mumkin.

```csharp
public string Index()
{
    // yangi event_handler yasaldi
    client.OnMessage += Xabar_Kelganda;
    
    //inline button bosilganda hosil
    // bo'ladigan event_handler 
    client.OnCallbackQuery += CallBack;

    // xabar kelishini tasdiqlash
    client.StartReceiving();
    
    return "Bot hozr ishlamoqda";
}


// callbackquery event_hand
private async void CallBack(object sender, CallbackQueryEventArgs e)
{
     if(e.CallbackQuery.Data == "A bosildi")
         await client
            .SendTextMessageAsync(e.CallbackQuery.From.Id, e.CallbackQuery.Data);
}

private async void Xabar_Kelganda(object sender, MessageEventArgs e)
{
    if (e.Message.Text == "test")
    {
        var markup = new InlineKeyboardMarkup(
            new InlineKeyboardButton[][]
            {
                new InlineKeyboardButton[]
                {
                    InlineKeyboardButton
                        .WithCallbackData(text: "A", callbackData: "A bosildi"),
                    
                    InlineKeyboardButton
                        .WithCallbackData(text: "B", callbackData: "B bosildi")
                },
                new InlineKeyboardButton[]
                {
                    InlineKeyboardButton
                        .WithCallbackData(text: "C", callbackData: "C bosildi"),
                    InlineKeyboardButton
                        .WithCallbackData(text: "D", callbackData: "D bosildi")
                }
            }
        );

                await client.SendTextMessageAsync(
                        chatId: e.Message.Chat.Id, 
                        text: "1 - test",
                        replyMarkup: markup
                    );            
            }
        }
```

**Natija:**

![](https://2189654329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-ML4YbrwilsjU6IyB7jd%2F-MRL5_fUM3RLoV71B8ff%2F-MRLAvt6pa4rFSt1FDAn%2Fimage.png?alt=media\&token=8f0fb227-0aac-41cf-9169-258122c58485)

**OnCallBackQuery** - InlineKeyboardButton bosilganda hosil bo'ladigan xodisa hisoblanadi. Ko'rib turganingizdek biz ham bu xodisa ishlagan paytda, **CallBack()** deb nomlangan event\_handler funksiyaga murojaat qilishni ko'rsatib qo'ydik.

InlineKeyboardButton sinfiga mansub bir nechta metodlar mavjud, yuqoridagi misolda **WithCallbackData()** ko'rinishidan foydalanildi. Ushbu metoddan joy olgan **callbackData** maydoni orqali keyingi vazifani belgilashga muvaffaq bo'ldik.

{% hint style="info" %}
E'tiborli bo'ling, callbackdata maydoni - 1 - 64 baytgacha bo'lgan oraliqni qabul qila oladi.
{% endhint %}

Endigi navbatda, tugmalarni dinamik holatda hosil qilishni ko'rib chiqamiz.

```csharp
if (e.Message.Text == "tugmalar")
{
    // jagged massivini hosil qilish
    InlineKeyboardButton[][] button = new InlineKeyboardButton[2][];
    button[0] = new InlineKeyboardButton[5];
    button[1] = new InlineKeyboardButton[5];
    for (int i = 0; i < 10; i++)
    {
        if (i < button[0].Length)
        {
            // 1 - massiv
            button[0][i] = new InlineKeyboardButton
                            { 
                                Text = (i + 1).ToString(), 
                                CallbackData = (i + 1).ToString() 
                            };
        }
        else
        {
            // 2 - massiv
            button[1][i - button[0].Length] = new InlineKeyboardButton 
                                                { 
                                                    Text = (i + 1).ToString(), 
                                                    CallbackData = (i + 1).ToString()
                                                 };
        }
    }
    var markup = new InlineKeyboardMarkup(button);

    await client.SendTextMessageAsync(
        chatId: e.Message.Chat.Id, 
        text: "Tugmalar",
        replyMarkup: markup
    );            
}
```

**Natija:**

![](https://2189654329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-ML4YbrwilsjU6IyB7jd%2F-MRL5_fUM3RLoV71B8ff%2F-MRLHlm5jgsW10p9w21C%2Fimage.png?alt=media\&token=b2688aae-ff6d-4bad-b5ca-cb19f8bfd8fb)

Tugmalarni 2 ta ustunda ham hosil qilishimiz mumkin. Endi, boshqacharoq yo'l bilan hosil qilib ko'ramiz

```csharp
if (e.Message.Text == "tugmalar")
{
    List<InlineKeyboardButton> buttons = new List<InlineKeyboardButton>();
    for (int i = 0; i < 10; i++)
    {
        buttons.Add(new InlineKeyboardButton 
                    { 
                        Text = (i + 1).ToString(), 
                        CallbackData = (i + 1).ToString()
                    });
    }

    var twoMenu = new List<InlineKeyboardButton[]>();
    for (var i = 0; i < buttons.Count; i ++)
    {
        if (buttons.Count - 1 == i)
        {
            twoMenu.Add(new[] { buttons[i] });
        }
        else
            twoMenu.Add(new[] { buttons[i], buttons[i + 1] });
        i++;
    }
                
    var markup = new InlineKeyboardMarkup(twoMenu.ToArray());
                
    await client.SendTextMessageAsync(
        chatId: e.Message.Chat.Id, 
        text: "Tugmalar",
        replyMarkup: markup
    );            
}
```

**Natija:**

![](https://2189654329-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-ML4YbrwilsjU6IyB7jd%2F-MRL5_fUM3RLoV71B8ff%2F-MRLK-2iVVrJU-9V2zzD%2Fimage.png?alt=media\&token=fdf8462e-2e33-4a93-8809-7fa945ef69a4)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.dot-net.uz/c-.net/telegram-bot/essential/klaviatura-bilan-ishlash/inlinekeyboardmarkup-inlinekeyboardbutton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
