Guest User

Guest User

  • Tech Writer
  • 529
  • 36.3k

how to insert dynamic button string and number value Help Me

Jul 13 2022 9:35 PM

This Button Already Make i will Select Any Button like B-149 is DutyspotName and 1 value Maxlimits 

i Will Make A New Button than i will try to save row and colums count than after save in database

Dynamic Button

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 = "Resverd " + 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;
    }
}
configurationBLL.AddDutySpot(spotname, row, col, maxlimit, rowspan, colspan, ison);

spotname this filed Name is txtSpotName.text

Row and Col find out what is last value 

maxlimits  this file name is numMaxlimits.Text

rowspan and colspan ind out what is last value 

ison value is RadioButton


Answers (1)