Paul Rajs

Paul Rajs

  • NA
  • 641
  • 147.3k

how do i Bind the dynamic controls on a buttonClick without

Feb 27 2018 3:01 AM

hi Developers ,

by using following query i want to bind the values on a ButtonClick

is it possibe means how can i , same structure but records bind on

if (IsPostBack)
{
BindRecords();

}

how can i do that .. ? i am tried but i did not get exact output

the problem i am get 1.the dynamic buttons are bind wo times or 2. no dynamic buttons binding, so give me some suggestion to do that

protected void Page_Load(object sender, EventArgs e)
{
string query = string.Format("SELECT roomno from AD_Rooms_Master order by roomno");
try
{
DataTable dt = GetData(query);
for (int i = 0; i < dt.Rows.Count; i++)
{
Button btn = new Button();
btn.ID = "btn" + (i + 1);
btn.Text = dt.Rows[i]["roomno"].ToString();
btn.Click += btnLoadButton_Click;
pnl_btns.Controls.Add(btn);
}
}
catch (Exception ex)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Error occured : " + ex.Message.ToString() + "');", true);
}
finally
{
//cmd = null;
//conn.Close();
}
}

protected void btnLoadButton_Click(object sender, EventArgs e)
{
ClientScript.RegisterClientScriptBlock(this.GetType(), "button", "<script type = 'text/javascript'>alert('Room no " + (sender as Button).Text + " selected');</script>");
}

thanking you

Paul.S

'man becomes what he thinks about'