shah Momin

shah Momin

  • NA
  • 176
  • 22.2k

Insert dynamic button save in Sql Server

Jul 12 2022 9:22 PM
int Count = 1;

private void BtnNewDutySpot_Click(object sender, EventArgs e)
{

    int Maxlimits = 1;
    try
    {
        Button btn = new Button();
        Count +=1;
        btn.Dock = DockStyle.Fill;
        btn.BackColor = Color.FromArgb(48, 56, 67);
        btn.ForeColor = System.Drawing.Color.White;
        btn.Name = "Reserved" + Count;
        btn.Text = "Reserved " +Count+  Environment.NewLine + Maxlimits;
        tblDutySpot.Controls.Add(btn);
        btn.Click += new System.EventHandler(btn_Click);
    }
    catch(Exception ex)
    {
        int num3 = (int)bunifuSnackbar1.Show(this, ex.Message, Bunifu.UI.WinForms.BunifuSnackbar.MessageTypes.Error, 3000, "X");

    }
}
private void btn_Click(object sender,EventArgs e)
{
    Button btn = (Button)sender;
    lblSpotID.Text = btn.Name;
    string[] strArray = btn.Text.Split(new string[1]
    {
    Environment.NewLine
    } , StringSplitOptions.RemoveEmptyEntries);
    txtSpotName.Text = strArray[0];
    numMaxLimit.Text = Convert.ToString(Convert.ToDecimal(strArray[1]));
    lblSpotRow.Text = tblDutySpot.GetRow((Control)btn).ToString();
    lblSpotCol.Text = tblDutySpot.GetColumn((Control)btn).ToString();
    if (btn.BackColor == Color.Red)
    {
        rbtnOffSpot.Checked = true;
        rbtnOnSpot.Checked = false;
    }
    else
    {
        rbtnOnSpot.Checked = true;
        rbtnOffSpot.Checked = false;
    }
}

Answers (2)