0

Here is my problem
A datalist and item template created at run time in asp.net when change value of textbox under datalist item template and page postback due to textchanged event but the datalist drop and datalist created again in pageload and textbox value drop.

void CreateDL(Control container)
    {
        var st = settings.CustomPossition();
        foreach (var item in settings.CustomPossition())
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Name");
            dt.Columns.Add("Possition");
            dt.Columns.Add("Production");
            dt.Columns.Add("dpo");
            dt.Columns.Add("WorkDay");
            DataRow dr;
            foreach (var users in item.Users)
            {

                dr = dt.NewRow();
                dr["Name"] = users.Name;
                dr["Possition"] = users.Position.Name;
                dr["Production"] = users.DailyGoalAmount * users.WorkDays;
                dr["dpo"] = users.DailyGoalAmount;
                dr["WorkDay"] = users.WorkDays;
                dt.Rows.Add(dr);
                dt.AcceptChanges();

            }
            DataList dataList = new DataList();      
         //   dataList.ItemTemplate = Page.LoadTemplate("Commnets.ascx");
            container.Controls.Add(dataList);

            dataList.DataSource = dt;
            dataList.DataBind();
        }
    }

how i can access value of textbox.

4

1 回答 1

0

检查 Page.IsPostBack:

if(!Page.IsPostBack)
{
//Your code
}
else
{
//Other code
}
于 2012-12-01T10:11:32.933 回答