Here i am developing slots booking application using asp.net and C# . Poblem is my dynamically created button is not firing oncommand in a repeater control. (book button) without repeater i have created dynamic buttons and after and i recreated them using protected override void LoadViewState(object savedState).
but here am unable to get any idea how to recreate it because here i am loading checkboxes and button if it is only possible to recreate it then how to do it please help me i am scratching my head from 3days here is my code behind
protected void grounds_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName == "btn")
{
Panel pl = (Panel)e.Item.FindControl("slotspanel");
Button book = new Button();
// Panel pl2 = (Panel)e.Item.FindControl("backgroundpanel");
LinkButton lb = new LinkButton();
LiteralControl lineBreak = new LiteralControl("<br/>");
int listItemIds = 1;
HtmlGenericControl ul = new HtmlGenericControl("ul");
DataSet ds = new DataSet();
ds = obj.getslots(1, "2014-10-10");
if (ds != null)
{
if (ds.Tables[1].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[1].Rows.Count; i++)
{
HtmlGenericControl li = new HtmlGenericControl("li");
CheckBox chk = new CheckBox();
HiddenField hd = new HiddenField();
// LinkButton lnk = new LinkButton();
chk.ID = "chk" + listItemIds;
hd.ID = "hd" + listItemIds;
chk.Text = ds.Tables[1].Rows[i]["slottimings"].ToString();
hd.Value = ds.Tables[1].Rows[i]["Type"].ToString();
// lnk.Click += Clicked;
//lnk.Command += new CommandEventHandler(lnkColourAlternative_Click);
//lnk.Click
li.Controls.Add(chk);
ul.Controls.Add(li);
listItemIds++;
}
}
}
HtmlGenericControl li2 = new HtmlGenericControl("li");
book.ID = "bookbutton";
book.Text = "Book";
book.CommandName = "Book";
book.EnableViewState = true;
book.UseSubmitBehavior = false;
HiddenField count = new HiddenField();
count.Value = (listItemIds-1).ToString();
count.ID = "hiddencount";
li2.Controls.Add(book);
ul.Controls.Add(li2);
pl.Controls.Add(ul);
pl.Controls.Add(lineBreak);
//pl2.Visible = true;
}
if (e.CommandName == "book")
{
if (Session["emailid"] != null)
{
HiddenField hd = (HiddenField)e.Item.FindControl("hiddencount");
int r = Convert.ToInt16(hd.Value);
int cost = 0;
string slots = string.Empty;
DataSet ds = new DataSet();
ds = obj.getgrounddetails(1, Session["sportsname"].ToString());
for (int i = 1; i <= r; i++)
{
CheckBox chk = (CheckBox)e.Item.FindControl("chk" + i);
HiddenField hhd = (HiddenField)e.Item.FindControl("hd" + i);
if (chk.Checked)
{
//type = hhd.Value;
cost = cost + Convert.ToInt16(ds.Tables[1].Rows[i][hhd.Value].ToString());
slots = slots + chk.Text;
}
}
Session["cost"] = cost.ToString();
Session["slots"] = slots;
Response.Redirect("payment/payment.aspx");
}
else
{
}
}
}
Thanks in Advance